Enable keyboard mode changer in wayland environment
[platform/core/uifw/isf.git] / ism / extras / kbd_mode_changer / main.cpp
1 /*
2  * ISF(Input Service Framework)
3  *
4  * ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable.
5  * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
6  *
7  * Contact: Wonkeun Oh <wonkeun.oh@samsung.com>, Jihoon Kim <jihoon48.kim@samsung.com>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation, Inc., 51
21  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24
25 #if HAVE_ECORE_X
26 #include <Ecore_X.h>
27 #endif
28 #include "main.h"
29
30 typedef enum
31 {
32     TOOLBAR_KEYBOARD_MODE = 0,  /* Hardware keyboard ISE */
33     TOOLBAR_HELPER_MODE         /* Software keyboard ISE */
34 } TOOLBAR_MODE_T;
35
36 #define E_PROP_DEVICEMGR_INPUTWIN                        "DeviceMgr Input Window"
37 #define E_PROP_DEVICEMGR_CONTROLWIN                      "_ISF_CONTROL_WINDOW"
38 #define PROP_X_EXT_KEYBOARD_INPUT_DETECTED               "HW Keyboard Input Started"
39 #define PROP_X_EXT_KEYBOARD_EXIST                        "X External Keyboard Exist"
40
41 bool app_create (void *user_data)
42 {
43     LOGD ("app create\n");
44     return true;
45 }
46
47 void app_control (app_control_h app_control, void *user_data)
48 {
49     LOGD ("%s\n", __func__);
50
51 #if HAVE_ECOREX
52     Ecore_X_Atom       prop_x_keyboard_input_detected = 0;
53     TOOLBAR_MODE_T     kbd_mode = TOOLBAR_HELPER_MODE;
54     Ecore_X_Window     _control_win = 0;
55     Ecore_X_Window     _input_win = 0;
56     unsigned int val = 0;
57
58     LOGD ("isf_extra_hwkbd_module start\n");
59
60     Ecore_X_Atom atom = ecore_x_atom_get (E_PROP_DEVICEMGR_CONTROLWIN);
61     if (ecore_x_window_prop_xid_get (ecore_x_window_root_first_get (), atom, ECORE_X_ATOM_WINDOW, &_control_win, 1) >= 0) {
62         if (!prop_x_keyboard_input_detected)
63             prop_x_keyboard_input_detected = ecore_x_atom_get (PROP_X_EXT_KEYBOARD_INPUT_DETECTED);
64
65         if (ecore_x_window_prop_card32_get (_control_win, prop_x_keyboard_input_detected, &val, 1) > 0) {
66             if (val == 1) {
67                 kbd_mode = TOOLBAR_KEYBOARD_MODE;
68             } else {
69                 kbd_mode = TOOLBAR_HELPER_MODE;
70             }
71         } else {
72             kbd_mode = TOOLBAR_HELPER_MODE;
73         }
74
75         // get the input window
76         atom = ecore_x_atom_get (E_PROP_DEVICEMGR_INPUTWIN);
77         if (ecore_x_window_prop_xid_get (ecore_x_window_root_first_get (), atom, ECORE_X_ATOM_WINDOW, &_input_win, 1) >= 0) {
78             //Set the window property value;
79             if (kbd_mode == TOOLBAR_KEYBOARD_MODE) {
80                 val = 0;
81                 ecore_x_window_prop_card32_set (_input_win, ecore_x_atom_get (PROP_X_EXT_KEYBOARD_EXIST), &val, 1);
82                 LOGD ("keyboard mode is changed HW -> SW by isf-kbd-mode-changer\n");
83             }
84         }
85     }
86 #endif
87
88     ui_app_exit ();
89 }
90
91 void app_terminate (void *user_data)
92 {
93     LOGD ("app terminated\n");
94 }
95
96 int main (int argc, char *argv [])
97 {
98     ui_app_lifecycle_callback_s event_callback = {0,};
99
100     event_callback.create = app_create;
101     event_callback.terminate = app_terminate;
102     event_callback.app_control = app_control;
103
104     LOGD ("start org.tizen.isf-kbd-mode-changer\n");
105
106     return ui_app_main (argc, argv, &event_callback, NULL);
107 }