4 #include <lirc/lirc_client.h>
5 #include "layout_image.h"
9 struct lirc_config *config = NULL;
14 *-----------------------------------------------------------------------------
16 *-----------------------------------------------------------------------------
23 gtk_input_remove(input_tag);
24 lirc_freeconfig(config);
34 g_io_channel_close(gio_chan);
38 gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition,
41 LayoutWindow *lw = data;
47 /* LIRC code and corresponding geeqie command (and parameters)*/
51 /* parameters for geeqie command */
55 while ((ret = lirc_nextcode(&code)) == 0 && code)
57 while ((ret = lirc_code2char(config, code, &cmd)) == 0 && cmd)
59 if (g_strncasecmp("LEFT", cmd, 4) == 0)
62 while (g_ascii_isspace(*ptr)) ptr++;
65 if (i_parm <= 0) i_parm = 1;
68 else if (g_strncasecmp("RIGHT", cmd, 5) == 0)
71 while (g_ascii_isspace(*ptr)) ptr++;
74 if (i_parm <= 0) i_parm = 1;
77 else if (g_strncasecmp("UP", cmd, 2) == 0)
80 while (g_ascii_isspace(*ptr)) ptr++;
83 if (i_parm <= 0) i_parm = 1;
86 else if (g_strncasecmp("DOWN", cmd, 4) == 0)
89 while (g_ascii_isspace(*ptr)) ptr++;
92 if (i_parm <= 0) i_parm = 1;
95 else if (g_strcasecmp("PREV", cmd) == 0)
97 layout_image_prev(lw);
99 else if (g_strcasecmp("NEXT", cmd) == 0)
101 layout_image_next(lw);
103 else if (g_strncasecmp("ZOOM_IN", cmd, 7) == 0)
106 while (g_ascii_isspace(*ptr)) ptr++;
107 fl_parm = atoi(ptr) / 10.0;
109 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
110 layout_image_zoom_adjust(lw, fl_parm);
112 else if (g_strncasecmp("ZOOM_OUT", cmd, 8) == 0)
115 while (g_ascii_isspace(*ptr)) ptr++;
116 fl_parm = atoi(ptr) / 10.0;
118 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
119 layout_image_zoom_adjust(lw, -fl_parm);
121 else if (g_strcasecmp("ZOOM_MAX", cmd) == 0)
123 layout_image_zoom_set(lw, 0.0);
125 else if (g_strncasecmp("SET_ZOOM", cmd, 8) == 0)
128 while (g_ascii_isspace(*ptr)) ptr++;
131 if (i_parm <= 0) i_parm = 1;
132 layout_image_zoom_set(lw, 1.0);
134 else if (g_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0)
137 while (g_ascii_isspace(*ptr)) ptr++;
140 if (i_parm <= 0) i_parm = 1;
141 layout_image_zoom_set(lw, -i_parm);
143 else if (g_strcasecmp("FIRST", cmd) == 0)
145 layout_image_first(lw);
147 else if (g_strcasecmp("LAST", cmd) == 0)
149 layout_image_last(lw);
151 else if (g_strcasecmp("PAUSE", cmd) == 0)
153 layout_image_slideshow_pause_toggle(lw);
155 else if (g_strcasecmp("ROTATE_90", cmd) == 0)
157 layout_image_alter(lw, ALTER_ROTATE_90);
159 else if (g_strcasecmp("ROTATE_90_CC", cmd) == 0)
161 layout_image_alter(lw, ALTER_ROTATE_90_CC);
163 else if (g_strcasecmp("INFO", cmd) == 0)
165 layout_image_overlay_toggle(lw);
167 else if (g_strcasecmp("EXIT", cmd) == 0)
173 if (ret == -1) break;
177 layout_image_scroll(lw, x, y);
182 /* something went badly wrong */
183 fprintf(stderr, _("disconnected from LIRC\n"));
185 return (gboolean)FALSE;
187 return (gboolean)TRUE;
190 void layout_image_lirc_init(LayoutWindow *lw)
194 DEBUG_1("Initializing LIRC...");
195 lirc_fd = lirc_init(GQ_APPNAME_LC, get_debug_level() > 0);
198 fprintf(stderr, _("Could not init LIRC support\n"));
201 if (lirc_readconfig(NULL, &config, NULL) == -1)
205 _("could not read LIRC config file\n"
206 "please read the documentation of LIRC to \n"
207 "know how to create a proper config file\n"));
210 gio_chan = g_io_channel_unix_new(lirc_fd);
211 input_tag = g_io_add_watch(gio_chan, G_IO_IN,
212 lirc_input_callback, lw);
213 fcntl(lirc_fd, F_SETOWN, getpid());
214 flags = fcntl(lirc_fd, F_GETFL, 0);
215 if (flags != -1) fcntl(lirc_fd, F_SETFL, flags|O_NONBLOCK);
219 #endif /* HAVE_LIRC */