Mercurial > geeqie
comparison src/lirc.c @ 528:bf9c9e37adf4
Added LIRC patch written by Matteo Beniamino
author | nadvornik |
---|---|
date | Sun, 27 Apr 2008 20:05:11 +0000 |
parents | |
children | e8b28413ffbf |
comparison
equal
deleted
inserted
replaced
527:93a1730e4641 | 528:bf9c9e37adf4 |
---|---|
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 { | |
23 gtk_input_remove(input_tag); | |
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 { | |
34 g_io_channel_close(gio_chan); | |
35 } | |
36 } | |
37 | |
38 gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition, | |
39 gpointer data) | |
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 { | |
59 if (g_strncasecmp("LEFT", cmd, 4) == 0) | |
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 } | |
68 else if (g_strncasecmp("RIGHT", cmd, 5) == 0) | |
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 } | |
77 else if (g_strncasecmp("UP", cmd, 2) == 0) | |
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 } | |
86 else if (g_strncasecmp("DOWN", cmd, 4) == 0) | |
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 } | |
95 else if (g_strcasecmp("PREV", cmd) == 0) | |
96 { | |
97 layout_image_prev(lw); | |
98 } | |
99 else if (g_strcasecmp("NEXT", cmd) == 0) | |
100 { | |
101 layout_image_next(lw); | |
102 } | |
103 else if (g_strncasecmp("ZOOM_IN", cmd, 7) == 0) | |
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 } | |
112 else if (g_strncasecmp("ZOOM_OUT", cmd, 8) == 0) | |
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 } | |
121 else if (g_strcasecmp("ZOOM_MAX", cmd) == 0) | |
122 { | |
123 layout_image_zoom_set(lw, 0.0); | |
124 } | |
125 else if (g_strncasecmp("SET_ZOOM", cmd, 8) == 0) | |
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 } | |
134 else if (g_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0) | |
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 } | |
143 else if (g_strcasecmp("FIRST", cmd) == 0) | |
144 { | |
145 layout_image_first(lw); | |
146 } | |
147 else if (g_strcasecmp("LAST", cmd) == 0) | |
148 { | |
149 layout_image_last(lw); | |
150 } | |
151 else if (g_strcasecmp("PAUSE", cmd) == 0) | |
152 { | |
153 layout_image_slideshow_pause_toggle(lw); | |
154 } | |
155 else if (g_strcasecmp("ROTATE_90", cmd) == 0) | |
156 { | |
157 layout_image_alter(lw, ALTER_ROTATE_90); | |
158 } | |
159 else if (g_strcasecmp("ROTATE_90_CC", cmd) == 0) | |
160 { | |
161 layout_image_alter(lw, ALTER_ROTATE_90_CC); | |
162 } | |
163 else if (g_strcasecmp("INFO", cmd) == 0) | |
164 { | |
165 layout_image_overlay_toggle(lw); | |
166 } | |
167 else if (g_strcasecmp("EXIT", cmd) == 0) | |
168 { | |
169 exit_program(); | |
170 } | |
171 } | |
172 free(code); | |
173 if (ret == -1) break; | |
174 } | |
175 if (x != 0 || y!= 0) | |
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 */ |