528
|
1 #include "lirc.h"
|
|
2
|
|
3 #ifdef HAVE_LIRC
|
|
4 #include <lirc/lirc_client.h>
|
|
5 #include "layout_image.h"
|
|
6
|
|
7 gint lirc_fd = -1;
|
|
8 struct lirc_config *config = NULL;
|
|
9 guint input_tag;
|
|
10 GIOChannel *gio_chan;
|
|
11
|
|
12 /*
|
|
13 *-----------------------------------------------------------------------------
|
|
14 * LIRC callback
|
|
15 *-----------------------------------------------------------------------------
|
|
16 */
|
|
17
|
610
|
18 static void lirc_cleanup(void)
|
528
|
19 {
|
|
20 if (config)
|
|
21 {
|
603
|
22 g_source_remove(input_tag);
|
528
|
23 lirc_freeconfig(config);
|
|
24 config = NULL;
|
|
25 }
|
|
26 if (lirc_fd != -1)
|
|
27 {
|
|
28 lirc_deinit();
|
|
29 lirc_fd = -1;
|
|
30 }
|
|
31 if (gio_chan)
|
|
32 {
|
603
|
33 g_io_channel_shutdown(gio_chan, TRUE, NULL);
|
|
34 g_io_channel_unref(gio_chan);
|
528
|
35 }
|
|
36 }
|
|
37
|
610
|
38 static gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition,
|
|
39 gpointer data)
|
528
|
40 {
|
|
41 LayoutWindow *lw = data;
|
|
42 gchar *ptr;
|
|
43 gint ret;
|
|
44 gint x = 0;
|
|
45 gint y = 0;
|
|
46
|
|
47 /* LIRC code and corresponding geeqie command (and parameters)*/
|
|
48 gchar *code;
|
|
49 gchar *cmd;
|
|
50
|
|
51 /* parameters for geeqie command */
|
|
52 gint i_parm;
|
|
53 gfloat fl_parm;
|
|
54
|
|
55 while ((ret = lirc_nextcode(&code)) == 0 && code)
|
|
56 {
|
|
57 while ((ret = lirc_code2char(config, code, &cmd)) == 0 && cmd)
|
|
58 {
|
603
|
59 if (g_ascii_strncasecmp("LEFT", cmd, 4) == 0)
|
528
|
60 {
|
|
61 ptr = cmd + 4;
|
|
62 while (g_ascii_isspace(*ptr)) ptr++;
|
|
63 i_parm = atoi(ptr);
|
|
64
|
|
65 if (i_parm <= 0) i_parm = 1;
|
|
66 x -= i_parm;
|
|
67 }
|
603
|
68 else if (g_ascii_strncasecmp("RIGHT", cmd, 5) == 0)
|
528
|
69 {
|
|
70 ptr = cmd + 5;
|
|
71 while (g_ascii_isspace(*ptr)) ptr++;
|
|
72 i_parm = atoi(ptr);
|
|
73
|
|
74 if (i_parm <= 0) i_parm = 1;
|
|
75 x += i_parm;
|
|
76 }
|
603
|
77 else if (g_ascii_strncasecmp("UP", cmd, 2) == 0)
|
528
|
78 {
|
|
79 ptr = cmd + 2;
|
|
80 while (g_ascii_isspace(*ptr)) ptr++;
|
|
81 i_parm = atoi(ptr);
|
|
82
|
|
83 if (i_parm <= 0) i_parm = 1;
|
|
84 y -= i_parm;
|
|
85 }
|
603
|
86 else if (g_ascii_strncasecmp("DOWN", cmd, 4) == 0)
|
528
|
87 {
|
|
88 ptr = cmd + 4;
|
|
89 while (g_ascii_isspace(*ptr)) ptr++;
|
|
90 i_parm = atoi(ptr);
|
|
91
|
|
92 if (i_parm <= 0) i_parm = 1;
|
|
93 y += i_parm;
|
|
94 }
|
603
|
95 else if (g_ascii_strcasecmp("PREV", cmd) == 0)
|
528
|
96 {
|
|
97 layout_image_prev(lw);
|
|
98 }
|
603
|
99 else if (g_ascii_strcasecmp("NEXT", cmd) == 0)
|
528
|
100 {
|
|
101 layout_image_next(lw);
|
|
102 }
|
603
|
103 else if (g_ascii_strncasecmp("ZOOM_IN", cmd, 7) == 0)
|
528
|
104 {
|
|
105 ptr = cmd + 7;
|
|
106 while (g_ascii_isspace(*ptr)) ptr++;
|
|
107 fl_parm = atoi(ptr) / 10.0;
|
|
108
|
|
109 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
|
|
110 layout_image_zoom_adjust(lw, fl_parm);
|
|
111 }
|
603
|
112 else if (g_ascii_strncasecmp("ZOOM_OUT", cmd, 8) == 0)
|
528
|
113 {
|
|
114 ptr = cmd + 8;
|
|
115 while (g_ascii_isspace(*ptr)) ptr++;
|
|
116 fl_parm = atoi(ptr) / 10.0;
|
|
117
|
|
118 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
|
|
119 layout_image_zoom_adjust(lw, -fl_parm);
|
|
120 }
|
603
|
121 else if (g_ascii_strcasecmp("ZOOM_MAX", cmd) == 0)
|
528
|
122 {
|
|
123 layout_image_zoom_set(lw, 0.0);
|
|
124 }
|
603
|
125 else if (g_ascii_strncasecmp("SET_ZOOM", cmd, 8) == 0)
|
528
|
126 {
|
|
127 ptr = cmd + 8;
|
|
128 while (g_ascii_isspace(*ptr)) ptr++;
|
|
129 i_parm = atoi(ptr);
|
|
130
|
|
131 if (i_parm <= 0) i_parm = 1;
|
|
132 layout_image_zoom_set(lw, 1.0);
|
|
133 }
|
603
|
134 else if (g_ascii_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0)
|
528
|
135 {
|
|
136 ptr = cmd + 12;
|
|
137 while (g_ascii_isspace(*ptr)) ptr++;
|
|
138 i_parm = atoi(ptr);
|
|
139
|
|
140 if (i_parm <= 0) i_parm = 1;
|
|
141 layout_image_zoom_set(lw, -i_parm);
|
|
142 }
|
603
|
143 else if (g_ascii_strcasecmp("FIRST", cmd) == 0)
|
528
|
144 {
|
|
145 layout_image_first(lw);
|
|
146 }
|
603
|
147 else if (g_ascii_strcasecmp("LAST", cmd) == 0)
|
528
|
148 {
|
|
149 layout_image_last(lw);
|
|
150 }
|
603
|
151 else if (g_ascii_strcasecmp("PAUSE", cmd) == 0)
|
528
|
152 {
|
|
153 layout_image_slideshow_pause_toggle(lw);
|
|
154 }
|
603
|
155 else if (g_ascii_strcasecmp("ROTATE_90", cmd) == 0)
|
528
|
156 {
|
|
157 layout_image_alter(lw, ALTER_ROTATE_90);
|
|
158 }
|
603
|
159 else if (g_ascii_strcasecmp("ROTATE_90_CC", cmd) == 0)
|
528
|
160 {
|
|
161 layout_image_alter(lw, ALTER_ROTATE_90_CC);
|
|
162 }
|
603
|
163 else if (g_ascii_strcasecmp("INFO", cmd) == 0)
|
528
|
164 {
|
|
165 layout_image_overlay_toggle(lw);
|
|
166 }
|
603
|
167 else if (g_ascii_strcasecmp("EXIT", cmd) == 0)
|
528
|
168 {
|
|
169 exit_program();
|
|
170 }
|
|
171 }
|
|
172 free(code);
|
|
173 if (ret == -1) break;
|
|
174 }
|
610
|
175 if (x != 0 || y != 0)
|
528
|
176 {
|
|
177 layout_image_scroll(lw, x, y);
|
|
178 }
|
|
179
|
|
180 if (ret == -1)
|
|
181 {
|
|
182 /* something went badly wrong */
|
|
183 fprintf(stderr, _("disconnected from LIRC\n"));
|
|
184 lirc_cleanup();
|
|
185 return (gboolean)FALSE;
|
|
186 }
|
|
187 return (gboolean)TRUE;
|
|
188 }
|
|
189
|
|
190 void layout_image_lirc_init(LayoutWindow *lw)
|
|
191 {
|
|
192 int flags;
|
|
193
|
|
194 DEBUG_1("Initializing LIRC...");
|
|
195 lirc_fd = lirc_init(GQ_APPNAME_LC, get_debug_level() > 0);
|
|
196 if (lirc_fd == -1)
|
|
197 {
|
|
198 fprintf(stderr, _("Could not init LIRC support\n"));
|
|
199 return;
|
|
200 }
|
|
201 if (lirc_readconfig(NULL, &config, NULL) == -1)
|
|
202 {
|
|
203 lirc_deinit();
|
|
204 fprintf(stderr,
|
|
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"));
|
|
208 return;
|
|
209 }
|
|
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);
|
|
216 fflush(stderr);
|
|
217 }
|
|
218
|
|
219 #endif /* HAVE_LIRC */
|