Mercurial > geeqie.yaz
annotate src/lirc.c @ 1668:9e168ba1b0b9
fixed an use of uninitialized value
author | nadvornik |
---|---|
date | Tue, 30 Jun 2009 20:15:33 +0000 |
parents | 24ef7b610ed6 |
children | d8e9d0cc640e |
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 } |
603 | 135 else if (g_ascii_strncasecmp("SET_ZOOM", cmd, 8) == 0) |
528 | 136 { |
137 ptr = cmd + 8; | |
138 while (g_ascii_isspace(*ptr)) ptr++; | |
139 i_parm = atoi(ptr); | |
140 | |
141 if (i_parm <= 0) i_parm = 1; | |
1047 | 142 layout_image_zoom_set(lw, 1.0, FALSE); |
528 | 143 } |
603 | 144 else if (g_ascii_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0) |
528 | 145 { |
146 ptr = cmd + 12; | |
147 while (g_ascii_isspace(*ptr)) ptr++; | |
148 i_parm = atoi(ptr); | |
149 | |
150 if (i_parm <= 0) i_parm = 1; | |
1047 | 151 layout_image_zoom_set(lw, -i_parm, FALSE); |
528 | 152 } |
603 | 153 else if (g_ascii_strcasecmp("FIRST", cmd) == 0) |
528 | 154 { |
155 layout_image_first(lw); | |
156 } | |
603 | 157 else if (g_ascii_strcasecmp("LAST", cmd) == 0) |
528 | 158 { |
159 layout_image_last(lw); | |
160 } | |
603 | 161 else if (g_ascii_strcasecmp("PAUSE", cmd) == 0) |
528 | 162 { |
163 layout_image_slideshow_pause_toggle(lw); | |
164 } | |
603 | 165 else if (g_ascii_strcasecmp("ROTATE_90", cmd) == 0) |
528 | 166 { |
1580
24ef7b610ed6
Backed out changeset 3d9f5c078521
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1566
diff
changeset
|
167 layout_image_alter(lw, ALTER_ROTATE_90); |
528 | 168 } |
603 | 169 else if (g_ascii_strcasecmp("ROTATE_90_CC", 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_CC); |
528 | 172 } |
603 | 173 else if (g_ascii_strcasecmp("INFO", cmd) == 0) |
528 | 174 { |
175 layout_image_overlay_toggle(lw); | |
176 } | |
603 | 177 else if (g_ascii_strcasecmp("EXIT", cmd) == 0) |
528 | 178 { |
179 exit_program(); | |
180 } | |
181 } | |
182 free(code); | |
183 if (ret == -1) break; | |
184 } | |
610 | 185 if (x != 0 || y != 0) |
528 | 186 { |
1265 | 187 layout_image_scroll(lw, x, y, FALSE); |
528 | 188 } |
189 | |
190 if (ret == -1) | |
191 { | |
192 /* something went badly wrong */ | |
1305 | 193 g_fprintf(stderr, _("disconnected from LIRC\n")); |
528 | 194 lirc_cleanup(); |
195 return (gboolean)FALSE; | |
196 } | |
197 return (gboolean)TRUE; | |
198 } | |
199 | |
200 void layout_image_lirc_init(LayoutWindow *lw) | |
201 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
202 gint flags; |
528 | 203 |
204 DEBUG_1("Initializing LIRC..."); | |
205 lirc_fd = lirc_init(GQ_APPNAME_LC, get_debug_level() > 0); | |
206 if (lirc_fd == -1) | |
207 { | |
1305 | 208 g_fprintf(stderr, _("Could not init LIRC support\n")); |
528 | 209 return; |
210 } | |
211 if (lirc_readconfig(NULL, &config, NULL) == -1) | |
212 { | |
213 lirc_deinit(); | |
1305 | 214 g_fprintf(stderr, |
528 | 215 _("could not read LIRC config file\n" |
216 "please read the documentation of LIRC to \n" | |
217 "know how to create a proper config file\n")); | |
218 return; | |
219 } | |
220 gio_chan = g_io_channel_unix_new(lirc_fd); | |
221 input_tag = g_io_add_watch(gio_chan, G_IO_IN, | |
995 | 222 lirc_input_callback, lw); |
528 | 223 fcntl(lirc_fd, F_SETOWN, getpid()); |
224 flags = fcntl(lirc_fd, F_GETFL, 0); | |
225 if (flags != -1) fcntl(lirc_fd, F_SETFL, flags|O_NONBLOCK); | |
226 fflush(stderr); | |
227 } | |
228 | |
229 #endif /* HAVE_LIRC */ | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1047
diff
changeset
|
230 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |