Mercurial > geeqie.yaz
annotate src/lirc.c @ 1743:d8e9d0cc640e
Allow to switch to fullscreen mode using LIRC.
Imagine the following situation (which happened to me several times) :
you want to see photos from your bed or your sofa so you launch geeqie
and go to the right directory, then you take your remote control and sit
comfortably far from your keyboard and mouse. And when you want to begin
to watch photos, you realize you forgot to enable full screen! You have
to stand up and to go until your computer and come back, whereas you
could have done it with your remote control.
Patch by Bernard Massot.
author | zas_ |
---|---|
date | Tue, 05 Jan 2010 17:49:50 +0000 |
parents | 24ef7b610ed6 |
children |
rev | line source |
---|---|
1305 | 1 /* |
2 * Geeqie | |
3 * Copyright (C) 2008 - 2009 The Geeqie Team | |
4 * | |
5 */ | |
6 | |
7 #include <glib/gprintf.h> | |
8 | |
528 | 9 #include "lirc.h" |
10 | |
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
1000
diff
changeset
|
11 #include "misc.h" |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
1000
diff
changeset
|
12 |
528 | 13 #ifdef HAVE_LIRC |
14 #include <lirc/lirc_client.h> | |
15 #include "layout_image.h" | |
16 | |
17 gint lirc_fd = -1; | |
18 struct lirc_config *config = NULL; | |
1523 | 19 guint input_tag = 0; /* event source id */ |
528 | 20 GIOChannel *gio_chan; |
21 | |
22 /* | |
23 *----------------------------------------------------------------------------- | |
24 * LIRC callback | |
25 *----------------------------------------------------------------------------- | |
26 */ | |
27 | |
610 | 28 static void lirc_cleanup(void) |
528 | 29 { |
30 if (config) | |
31 { | |
603 | 32 g_source_remove(input_tag); |
528 | 33 lirc_freeconfig(config); |
34 config = NULL; | |
35 } | |
36 if (lirc_fd != -1) | |
37 { | |
38 lirc_deinit(); | |
39 lirc_fd = -1; | |
40 } | |
41 if (gio_chan) | |
42 { | |
603 | 43 g_io_channel_shutdown(gio_chan, TRUE, NULL); |
44 g_io_channel_unref(gio_chan); | |
528 | 45 } |
46 } | |
47 | |
610 | 48 static gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition, |
49 gpointer data) | |
528 | 50 { |
51 LayoutWindow *lw = data; | |
52 gchar *ptr; | |
53 gint ret; | |
54 gint x = 0; | |
55 gint y = 0; | |
56 | |
57 /* LIRC code and corresponding geeqie command (and parameters)*/ | |
58 gchar *code; | |
59 gchar *cmd; | |
60 | |
61 /* parameters for geeqie command */ | |
62 gint i_parm; | |
63 gfloat fl_parm; | |
64 | |
65 while ((ret = lirc_nextcode(&code)) == 0 && code) | |
66 { | |
67 while ((ret = lirc_code2char(config, code, &cmd)) == 0 && cmd) | |
68 { | |
603 | 69 if (g_ascii_strncasecmp("LEFT", cmd, 4) == 0) |
528 | 70 { |
71 ptr = cmd + 4; | |
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("RIGHT", cmd, 5) == 0) |
528 | 79 { |
80 ptr = cmd + 5; | |
81 while (g_ascii_isspace(*ptr)) ptr++; | |
82 i_parm = atoi(ptr); | |
83 | |
84 if (i_parm <= 0) i_parm = 1; | |
85 x += i_parm; | |
86 } | |
603 | 87 else if (g_ascii_strncasecmp("UP", cmd, 2) == 0) |
528 | 88 { |
89 ptr = cmd + 2; | |
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_strncasecmp("DOWN", cmd, 4) == 0) |
528 | 97 { |
98 ptr = cmd + 4; | |
99 while (g_ascii_isspace(*ptr)) ptr++; | |
100 i_parm = atoi(ptr); | |
101 | |
102 if (i_parm <= 0) i_parm = 1; | |
103 y += i_parm; | |
104 } | |
603 | 105 else if (g_ascii_strcasecmp("PREV", cmd) == 0) |
528 | 106 { |
107 layout_image_prev(lw); | |
108 } | |
603 | 109 else if (g_ascii_strcasecmp("NEXT", cmd) == 0) |
528 | 110 { |
111 layout_image_next(lw); | |
112 } | |
603 | 113 else if (g_ascii_strncasecmp("ZOOM_IN", cmd, 7) == 0) |
528 | 114 { |
115 ptr = cmd + 7; | |
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(); | |
1047 | 120 layout_image_zoom_adjust(lw, fl_parm, FALSE); |
528 | 121 } |
603 | 122 else if (g_ascii_strncasecmp("ZOOM_OUT", cmd, 8) == 0) |
528 | 123 { |
124 ptr = cmd + 8; | |
125 while (g_ascii_isspace(*ptr)) ptr++; | |
126 fl_parm = atoi(ptr) / 10.0; | |
127 | |
128 if (fl_parm <= 0.01) fl_parm = get_zoom_increment(); | |
1047 | 129 layout_image_zoom_adjust(lw, -fl_parm, FALSE); |
528 | 130 } |
603 | 131 else if (g_ascii_strcasecmp("ZOOM_MAX", cmd) == 0) |
528 | 132 { |
1047 | 133 layout_image_zoom_set(lw, 0.0, FALSE); |
528 | 134 } |
1743 | 135 else if (g_ascii_strcasecmp("FULL_SCREEN", cmd) == 0) |
136 { | |
137 layout_image_full_screen_toggle(lw); | |
138 } | |
603 | 139 else if (g_ascii_strncasecmp("SET_ZOOM", cmd, 8) == 0) |
528 | 140 { |
141 ptr = cmd + 8; | |
142 while (g_ascii_isspace(*ptr)) ptr++; | |
143 i_parm = atoi(ptr); | |
144 | |
145 if (i_parm <= 0) i_parm = 1; | |
1047 | 146 layout_image_zoom_set(lw, 1.0, FALSE); |
528 | 147 } |
603 | 148 else if (g_ascii_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0) |
528 | 149 { |
150 ptr = cmd + 12; | |
151 while (g_ascii_isspace(*ptr)) ptr++; | |
152 i_parm = atoi(ptr); | |
153 | |
154 if (i_parm <= 0) i_parm = 1; | |
1047 | 155 layout_image_zoom_set(lw, -i_parm, FALSE); |
528 | 156 } |
603 | 157 else if (g_ascii_strcasecmp("FIRST", cmd) == 0) |
528 | 158 { |
159 layout_image_first(lw); | |
160 } | |
603 | 161 else if (g_ascii_strcasecmp("LAST", cmd) == 0) |
528 | 162 { |
163 layout_image_last(lw); | |
164 } | |
603 | 165 else if (g_ascii_strcasecmp("PAUSE", cmd) == 0) |
528 | 166 { |
167 layout_image_slideshow_pause_toggle(lw); | |
168 } | |
603 | 169 else if (g_ascii_strcasecmp("ROTATE_90", cmd) == 0) |
528 | 170 { |
1580
24ef7b610ed6
Backed out changeset 3d9f5c078521
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1566
diff
changeset
|
171 layout_image_alter(lw, ALTER_ROTATE_90); |
528 | 172 } |
603 | 173 else if (g_ascii_strcasecmp("ROTATE_90_CC", cmd) == 0) |
528 | 174 { |
1580
24ef7b610ed6
Backed out changeset 3d9f5c078521
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1566
diff
changeset
|
175 layout_image_alter(lw, ALTER_ROTATE_90_CC); |
528 | 176 } |
603 | 177 else if (g_ascii_strcasecmp("INFO", cmd) == 0) |
528 | 178 { |
179 layout_image_overlay_toggle(lw); | |
180 } | |
603 | 181 else if (g_ascii_strcasecmp("EXIT", cmd) == 0) |
528 | 182 { |
183 exit_program(); | |
184 } | |
185 } | |
186 free(code); | |
187 if (ret == -1) break; | |
188 } | |
610 | 189 if (x != 0 || y != 0) |
528 | 190 { |
1265 | 191 layout_image_scroll(lw, x, y, FALSE); |
528 | 192 } |
193 | |
194 if (ret == -1) | |
195 { | |
196 /* something went badly wrong */ | |
1305 | 197 g_fprintf(stderr, _("disconnected from LIRC\n")); |
528 | 198 lirc_cleanup(); |
199 return (gboolean)FALSE; | |
200 } | |
201 return (gboolean)TRUE; | |
202 } | |
203 | |
204 void layout_image_lirc_init(LayoutWindow *lw) | |
205 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
206 gint flags; |
528 | 207 |
208 DEBUG_1("Initializing LIRC..."); | |
209 lirc_fd = lirc_init(GQ_APPNAME_LC, get_debug_level() > 0); | |
210 if (lirc_fd == -1) | |
211 { | |
1305 | 212 g_fprintf(stderr, _("Could not init LIRC support\n")); |
528 | 213 return; |
214 } | |
215 if (lirc_readconfig(NULL, &config, NULL) == -1) | |
216 { | |
217 lirc_deinit(); | |
1305 | 218 g_fprintf(stderr, |
528 | 219 _("could not read LIRC config file\n" |
220 "please read the documentation of LIRC to \n" | |
221 "know how to create a proper config file\n")); | |
222 return; | |
223 } | |
224 gio_chan = g_io_channel_unix_new(lirc_fd); | |
225 input_tag = g_io_add_watch(gio_chan, G_IO_IN, | |
995 | 226 lirc_input_callback, lw); |
528 | 227 fcntl(lirc_fd, F_SETOWN, getpid()); |
228 flags = fcntl(lirc_fd, F_GETFL, 0); | |
229 if (flags != -1) fcntl(lirc_fd, F_SETFL, flags|O_NONBLOCK); | |
230 fflush(stderr); | |
231 } | |
232 | |
233 #endif /* HAVE_LIRC */ | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1047
diff
changeset
|
234 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |