65b6743ed84965d07a185a1ddb97ff6fb737db77
[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 #include <Ecore_X.h>
26 #include "main.h"
27
28 typedef enum
29 {
30     TOOLBAR_KEYBOARD_MODE = 0,  /* Hardware keyboard ISE */
31     TOOLBAR_HELPER_MODE         /* Software keyboard ISE */
32 } TOOLBAR_MODE_T;
33
34 #define E_PROP_DEVICEMGR_INPUTWIN                        "DeviceMgr Input Window"
35 #define E_PROP_DEVICEMGR_CONTROLWIN                      "_ISF_CONTROL_WINDOW"
36 #define PROP_X_EXT_KEYBOARD_INPUT_DETECTED               "HW Keyboard Input Started"
37 #define PROP_X_EXT_KEYBOARD_EXIST                        "X External Keyboard Exist"
38
39 bool app_create (void *user_data)
40 {
41     LOGD ("app create\n");
42     return true;
43 }
44
45 void app_control (app_control_h app_control, void *user_data)
46 {
47     LOGD ("%s\n", __func__);
48
49     Ecore_X_Atom       prop_x_keyboard_input_detected = 0;
50     TOOLBAR_MODE_T     kbd_mode = TOOLBAR_HELPER_MODE;
51     Ecore_X_Window     _control_win = 0;
52     Ecore_X_Window     _input_win = 0;
53     unsigned int val = 0;
54
55     LOGD ("isf_extra_hwkbd_module start\n");
56
57     Ecore_X_Atom atom = ecore_x_atom_get (E_PROP_DEVICEMGR_CONTROLWIN);
58     if (ecore_x_window_prop_xid_get (ecore_x_window_root_first_get (), atom, ECORE_X_ATOM_WINDOW, &_control_win, 1) >= 0) {
59         if (!prop_x_keyboard_input_detected)
60             prop_x_keyboard_input_detected = ecore_x_atom_get (PROP_X_EXT_KEYBOARD_INPUT_DETECTED);
61
62         if (ecore_x_window_prop_card32_get (_control_win, prop_x_keyboard_input_detected, &val, 1) > 0) {
63             if (val == 1) {
64                 kbd_mode = TOOLBAR_KEYBOARD_MODE;
65             } else {
66                 kbd_mode = TOOLBAR_HELPER_MODE;
67             }
68         } else {
69             kbd_mode = TOOLBAR_HELPER_MODE;
70         }
71
72         // get the input window
73         atom = ecore_x_atom_get (E_PROP_DEVICEMGR_INPUTWIN);
74         if (ecore_x_window_prop_xid_get (ecore_x_window_root_first_get (), atom, ECORE_X_ATOM_WINDOW, &_input_win, 1) >= 0) {
75             //Set the window property value;
76             if (kbd_mode == TOOLBAR_KEYBOARD_MODE) {
77                 val = 0;
78                 ecore_x_window_prop_card32_set (_input_win, ecore_x_atom_get (PROP_X_EXT_KEYBOARD_EXIST), &val, 1);
79                 LOGD ("keyboard mode is changed HW -> SW by isf-kbd-mode-changer\n");
80             }
81         }
82     }
83
84     ui_app_exit ();
85 }
86
87 void app_terminate (void *user_data)
88 {
89     LOGD ("app terminated\n");
90 }
91
92 int main (int argc, char *argv [])
93 {
94     ui_app_lifecycle_callback_s event_callback = {0,};
95
96     event_callback.create = app_create;
97     event_callback.terminate = app_terminate;
98     event_callback.app_control = app_control;
99
100     LOGD ("start org.tizen.isf-kbd-mode-changer\n");
101
102     return ui_app_main (argc, argv, &event_callback, NULL);
103 }