1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Copyright (C) 2006-2016 XNeur Team
17 *
18 */
19
20 #include <X11/XKBlib.h>
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "xneur.h"
27
28 #include "window.h"
29 #include "keymap.h"
30
31 #include "types.h"
32 #include "utils.h"
33 #include "log.h"
34
35 #include "switchlang.h"
36
37 extern struct _window *main_window;
38
get_curr_keyboard_group(void)39 int get_curr_keyboard_group(void)
40 {
41 XkbStateRec xkbState;
42 XkbGetState(main_window->display, XkbUseCoreKbd, &xkbState);
43 int group = xkbState.group;
44 //XFree(xkbState);
45 return group;
46 }
47
set_keyboard_group(int layout_group)48 void set_keyboard_group(int layout_group)
49 {
50 XkbLockGroup(main_window->display, XkbUseCoreKbd, layout_group);
51
52 //Gsettings hack
53 /*char *gsettings_command = malloc(1024 * sizeof(char));
54 sprintf(gsettings_command, "gsettings set org.gnome.desktop.input-sources current %d", layout_group);
55 log_message (DEBUG, gsettings_command);
56 if (system(gsettings_command)) {};*/
57 }
58
set_next_keyboard_group(struct _xneur_handle * handle)59 void set_next_keyboard_group(struct _xneur_handle *handle)
60 {
61 int new_layout_group = get_curr_keyboard_group() + 1;
62 if (new_layout_group == handle->total_languages)
63 new_layout_group = 0;
64 XkbLockGroup(main_window->display, XkbUseCoreKbd, new_layout_group);
65
66 //Gsettings hack
67 /*char *gsettings_command = malloc(1024 * sizeof(char));
68 sprintf(gsettings_command, "gsettings set org.gnome.desktop.input-sources current %d", new_layout_group);
69 log_message (DEBUG, gsettings_command);
70 if (system(gsettings_command)) {};*/
71 }
72
set_prev_keyboard_group(struct _xneur_handle * handle)73 void set_prev_keyboard_group(struct _xneur_handle *handle)
74 {
75 int new_layout_group = get_curr_keyboard_group() - 1;
76 if (new_layout_group < 0)
77 new_layout_group = handle->total_languages - 1;
78 XkbLockGroup(main_window->display, XkbUseCoreKbd, new_layout_group);
79
80 // Gsettings hack
81 /*char *gsettings_command = malloc(1024 * sizeof(char));
82 sprintf(gsettings_command, "gsettings set org.gnome.desktop.input-sources current %d", new_layout_group);
83 log_message (DEBUG, gsettings_command);
84 if (system(gsettings_command)) {};*/
85 }
86