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