2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <glib/gprintf.h>
26 #include <lirc/lirc_client.h>
27 #include "layout_image.h"
30 struct lirc_config *config = NULL;
31 guint input_tag = 0; /* event source id */
35 *-----------------------------------------------------------------------------
37 *-----------------------------------------------------------------------------
40 static void lirc_cleanup(void)
44 g_source_remove(input_tag);
45 lirc_freeconfig(config);
55 g_io_channel_shutdown(gio_chan, TRUE, NULL);
56 g_io_channel_unref(gio_chan);
60 static gboolean lirc_input_callback(GIOChannel *source, GIOCondition condition,
63 LayoutWindow *lw = data;
69 /* LIRC code and corresponding geeqie command (and parameters)*/
73 /* parameters for geeqie command */
77 while ((ret = lirc_nextcode(&code)) == 0 && code)
79 while ((ret = lirc_code2char(config, code, &cmd)) == 0 && cmd)
81 if (g_ascii_strncasecmp("LEFT", cmd, 4) == 0)
84 while (g_ascii_isspace(*ptr)) ptr++;
87 if (i_parm <= 0) i_parm = 1;
90 else if (g_ascii_strncasecmp("RIGHT", cmd, 5) == 0)
93 while (g_ascii_isspace(*ptr)) ptr++;
96 if (i_parm <= 0) i_parm = 1;
99 else if (g_ascii_strncasecmp("UP", cmd, 2) == 0)
102 while (g_ascii_isspace(*ptr)) ptr++;
105 if (i_parm <= 0) i_parm = 1;
108 else if (g_ascii_strncasecmp("DOWN", cmd, 4) == 0)
111 while (g_ascii_isspace(*ptr)) ptr++;
114 if (i_parm <= 0) i_parm = 1;
117 else if (g_ascii_strcasecmp("PREV", cmd) == 0)
119 layout_image_prev(lw);
121 else if (g_ascii_strcasecmp("NEXT", cmd) == 0)
123 layout_image_next(lw);
125 else if (g_ascii_strncasecmp("ZOOM_IN", cmd, 7) == 0)
128 while (g_ascii_isspace(*ptr)) ptr++;
129 fl_parm = atoi(ptr) / 10.0;
131 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
132 layout_image_zoom_adjust(lw, fl_parm, FALSE);
134 else if (g_ascii_strncasecmp("ZOOM_OUT", cmd, 8) == 0)
137 while (g_ascii_isspace(*ptr)) ptr++;
138 fl_parm = atoi(ptr) / 10.0;
140 if (fl_parm <= 0.01) fl_parm = get_zoom_increment();
141 layout_image_zoom_adjust(lw, -fl_parm, FALSE);
143 else if (g_ascii_strcasecmp("ZOOM_MAX", cmd) == 0)
145 layout_image_zoom_set(lw, 0.0, FALSE);
147 else if (g_ascii_strcasecmp("FULL_SCREEN", cmd) == 0)
149 layout_image_full_screen_toggle(lw);
151 else if (g_ascii_strncasecmp("SET_ZOOM", cmd, 8) == 0)
154 while (g_ascii_isspace(*ptr)) ptr++;
157 if (i_parm <= 0) i_parm = 1;
158 layout_image_zoom_set(lw, 1.0, FALSE);
160 else if (g_ascii_strncasecmp("SET_INV_ZOOM", cmd, 12) == 0)
163 while (g_ascii_isspace(*ptr)) ptr++;
166 if (i_parm <= 0) i_parm = 1;
167 layout_image_zoom_set(lw, -i_parm, FALSE);
169 else if (g_ascii_strcasecmp("FIRST", cmd) == 0)
171 layout_image_first(lw);
173 else if (g_ascii_strcasecmp("LAST", cmd) == 0)
175 layout_image_last(lw);
177 else if (g_ascii_strcasecmp("PAUSE", cmd) == 0)
179 layout_image_slideshow_pause_toggle(lw);
181 else if (g_ascii_strcasecmp("ROTATE_90", cmd) == 0)
183 layout_image_alter_orientation(lw, ALTER_ROTATE_90);
185 else if (g_ascii_strcasecmp("ROTATE_90_CC", cmd) == 0)
187 layout_image_alter_orientation(lw, ALTER_ROTATE_90_CC);
189 else if (g_ascii_strcasecmp("INFO", cmd) == 0)
191 layout_image_overlay_toggle(lw);
193 else if (g_ascii_strcasecmp("EXIT", cmd) == 0)
199 if (ret == -1) break;
201 if (x != 0 || y != 0)
203 layout_image_scroll(lw, x, y, FALSE);
208 /* something went badly wrong */
209 g_fprintf(stderr, _("disconnected from LIRC\n"));
211 return (gboolean)FALSE;
213 return (gboolean)TRUE;
216 void layout_image_lirc_init(LayoutWindow *lw)
219 gboolean lirc_verbose = (get_debug_level() >= 2);
221 lirc_fd = lirc_init(GQ_APPNAME_LC, lirc_verbose);
224 DEBUG_1("Initializing LIRC... failed");
228 DEBUG_1("Initializing LIRC... OK");
229 if (lirc_readconfig(NULL, &config, NULL) == -1)
234 _("could not read LIRC config file\n"
235 "please read the documentation of LIRC to \n"
236 "know how to create a proper config file\n"));
239 DEBUG_1("Failed to read LIRC config file");
242 if (lirc_verbose) fflush(stderr);
244 gio_chan = g_io_channel_unix_new(lirc_fd);
245 input_tag = g_io_add_watch(gio_chan, G_IO_IN,
246 lirc_input_callback, lw);
247 fcntl(lirc_fd, F_SETOWN, getpid());
248 flags = fcntl(lirc_fd, F_GETFL, 0);
249 if (flags != -1) fcntl(lirc_fd, F_SETFL, flags|O_NONBLOCK);
252 #endif /* HAVE_LIRC */
253 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */