[E_BORDER] Add missing code to delete timer when the window gets DEICONIFY_APPROVE...
[platform/core/uifw/e17.git] / src / bin / e_focus.c
1 #include "e.h"
2
3 /* local subsystem functions */
4 static Eina_Bool _e_focus_raise_timer(void *data);
5
6 /* local subsystem globals */
7
8 /* externally accessible functions */
9 EINTERN int
10 e_focus_init(void)
11 {
12    return 1;
13 }
14
15 EINTERN int
16 e_focus_shutdown(void)
17 {
18    return 1;
19 }
20
21 EAPI void
22 e_focus_idler_before(void)
23 {
24    return;
25 }
26
27 EAPI void
28 e_focus_event_mouse_in(E_Border *bd)
29 {
30    if ((e_config->focus_policy == E_FOCUS_MOUSE) ||
31        (e_config->focus_policy == E_FOCUS_SLOPPY))
32      {
33         e_border_focus_set(bd, 1, 1);
34      }
35    if (bd->raise_timer) ecore_timer_del(bd->raise_timer);
36    bd->raise_timer = NULL;
37    if (e_config->use_auto_raise)
38      {
39         if (e_config->auto_raise_delay == 0.0)
40           {
41              if (!bd->lock_user_stacking)
42                {
43                   if (e_config->border_raise_on_focus)
44                     e_border_raise(bd);
45                }
46           }
47         else
48           bd->raise_timer = ecore_timer_add(e_config->auto_raise_delay, _e_focus_raise_timer, bd);
49      }
50 }
51
52 EAPI void
53 e_focus_event_mouse_out(E_Border *bd)
54 {
55    if (e_config->focus_policy == E_FOCUS_MOUSE)
56      {
57         /* FIXME: this is such a hack. its a big hack around x's async events
58          * as we dont know always exactly what action causes what event
59          * so by waiting more than 0.2 secs before reverting focus to nothing
60          * since we entered root, we are ignoring mouse in's on the root
61          * container for a bit after the mosue may have entered it
62          */
63         if ((ecore_loop_time_get() - e_grabinput_last_focus_time_get()) > 0.2)
64           {
65              if (!bd->lock_focus_in)
66                {
67                   if (bd->focused)
68                     e_border_focus_set(bd, 0, 1);
69                }
70           }
71      }
72    if (bd->raise_timer)
73      {
74         ecore_timer_del(bd->raise_timer);
75         bd->raise_timer = NULL;
76      }
77 }
78
79 EAPI void
80 e_focus_event_mouse_down(E_Border *bd)
81 {
82    if (e_config->focus_policy == E_FOCUS_CLICK)
83      {
84         e_border_focus_set(bd, 1, 1);
85
86         if (!bd->lock_user_stacking)
87           {
88              if (e_config->border_raise_on_focus)
89                e_border_raise(bd);
90           }
91      }
92    else if (e_config->always_click_to_raise)
93      {
94         if (!bd->lock_user_stacking)
95           {
96              if (e_config->border_raise_on_focus)
97                e_border_raise(bd);
98           }
99      }
100    else if (e_config->always_click_to_focus)
101      {
102         e_border_focus_set(bd, 1, 1);
103      }
104 }
105
106 EAPI void
107 e_focus_event_mouse_up(E_Border *bd __UNUSED__)
108 {
109 }
110
111 EAPI void
112 e_focus_event_focus_in(E_Border *bd)
113 {
114    if ((e_config->focus_policy == E_FOCUS_CLICK) &&
115        (!e_config->always_click_to_raise) &&
116        (!e_config->always_click_to_focus))
117      {
118         if (!bd->button_grabbed) return;
119         e_bindings_mouse_ungrab(E_BINDING_CONTEXT_WINDOW, bd->win);
120         e_bindings_wheel_ungrab(E_BINDING_CONTEXT_WINDOW, bd->win);
121         ecore_x_window_button_ungrab(bd->win, 1, 0, 1);
122         ecore_x_window_button_ungrab(bd->win, 2, 0, 1);
123         ecore_x_window_button_ungrab(bd->win, 3, 0, 1);
124         e_bindings_mouse_grab(E_BINDING_CONTEXT_WINDOW, bd->win);
125         e_bindings_wheel_grab(E_BINDING_CONTEXT_WINDOW, bd->win);
126         bd->button_grabbed = 0;
127      }
128 }
129
130 EAPI void
131 e_focus_event_focus_out(E_Border *bd)
132 {
133    if ((e_config->focus_policy == E_FOCUS_CLICK) &&
134        (!e_config->always_click_to_raise) &&
135        (!e_config->always_click_to_focus))
136      {
137         if (bd->button_grabbed) return;
138         ecore_x_window_button_grab(bd->win, 1,
139                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
140                                    ECORE_X_EVENT_MASK_MOUSE_UP |
141                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
142         ecore_x_window_button_grab(bd->win, 2,
143                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
144                                    ECORE_X_EVENT_MASK_MOUSE_UP |
145                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
146         ecore_x_window_button_grab(bd->win, 3,
147                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
148                                    ECORE_X_EVENT_MASK_MOUSE_UP |
149                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
150         bd->button_grabbed = 1;
151      }
152 }
153
154 EAPI void
155 e_focus_setup(E_Border *bd)
156 {
157    if ((e_config->focus_policy == E_FOCUS_CLICK) ||
158        (e_config->always_click_to_raise) ||
159        (e_config->always_click_to_focus))
160      {
161         if (bd->button_grabbed) return;
162         ecore_x_window_button_grab(bd->win, 1,
163                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
164                                    ECORE_X_EVENT_MASK_MOUSE_UP |
165                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
166         ecore_x_window_button_grab(bd->win, 2,
167                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
168                                    ECORE_X_EVENT_MASK_MOUSE_UP |
169                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
170         ecore_x_window_button_grab(bd->win, 3,
171                                    ECORE_X_EVENT_MASK_MOUSE_DOWN |
172                                    ECORE_X_EVENT_MASK_MOUSE_UP |
173                                    ECORE_X_EVENT_MASK_MOUSE_MOVE, 0, 1);
174         bd->button_grabbed = 1;
175      }
176 }
177
178 EAPI void
179 e_focus_setdown(E_Border *bd)
180 {
181    if (!bd->button_grabbed) return;
182    e_bindings_mouse_ungrab(E_BINDING_CONTEXT_WINDOW, bd->win);
183    e_bindings_wheel_ungrab(E_BINDING_CONTEXT_WINDOW, bd->win);
184    ecore_x_window_button_ungrab(bd->win, 1, 0, 1);
185    ecore_x_window_button_ungrab(bd->win, 2, 0, 1);
186    ecore_x_window_button_ungrab(bd->win, 3, 0, 1);
187    e_bindings_mouse_grab(E_BINDING_CONTEXT_WINDOW, bd->win);
188    e_bindings_wheel_grab(E_BINDING_CONTEXT_WINDOW, bd->win);
189    bd->button_grabbed = 0;
190 }
191
192 /* local subsystem functions */
193 static Eina_Bool
194 _e_focus_raise_timer(void *data)
195 {
196    E_Border *bd;
197
198    bd = data;
199    if (!bd->lock_user_stacking) e_border_raise(bd);
200    bd->raise_timer = NULL;
201    return ECORE_CALLBACK_CANCEL;
202 }
203