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