summaryrefslogtreecommitdiff
path: root/src/display.h
blob: a16bc5bc397e1d128c4a059b3cefb09b123c010a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/* Metacity X display handler */

/* 
 * Copyright (C) 2001 Havoc Pennington
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifndef META_DISPLAY_H
#define META_DISPLAY_H

#include <glib.h>
#include <X11/Xlib.h>
#include "eventqueue.h"
#include "common.h"

#define meta_XFree(p) do { if ((p)) XFree ((p)); } while (0)

/* this doesn't really belong here, oh well. */
typedef struct _MetaRectangle MetaRectangle;

struct _MetaRectangle
{
  int x;
  int y;
  int width;
  int height;
};

typedef struct _MetaDisplay    MetaDisplay;
typedef struct _MetaFrame      MetaFrame;
typedef struct _MetaKeyBinding MetaKeyBinding;
typedef struct _MetaScreen     MetaScreen;
typedef struct _MetaStack      MetaStack;
typedef struct _MetaUISlave    MetaUISlave;
typedef struct _MetaWindow     MetaWindow;
typedef struct _MetaWorkspace  MetaWorkspace;

typedef void (* MetaWindowPingFunc) (MetaDisplay *display,
				     Window       xwindow,
				     gpointer     user_data);


#define _NET_WM_STATE_REMOVE        0    /* remove/unset property */
#define _NET_WM_STATE_ADD           1    /* add/set property */
#define _NET_WM_STATE_TOGGLE        2    /* toggle property  */

/* This is basically a bogus number, just has to be large enough
 * to handle the expected case of the alt+tab operation, where
 * we want to ignore serials from UnmapNotify on the tab popup,
 * and the LeaveNotify/EnterNotify from the pointer ungrab
 */
#define N_IGNORED_SERIALS           4

struct _MetaDisplay
{
  char *name;
  Display *xdisplay;

  Window leader_window;
  
  Atom atom_net_wm_name;
  Atom atom_wm_protocols;
  Atom atom_wm_take_focus;
  Atom atom_wm_delete_window;
  Atom atom_wm_state;
  Atom atom_net_close_window;
  Atom atom_net_wm_state;
  Atom atom_motif_wm_hints;
  Atom atom_net_wm_state_shaded;
  Atom atom_net_wm_state_maximized_horz;
  Atom atom_net_wm_state_maximized_vert;
  Atom atom_net_wm_desktop;
  Atom atom_net_number_of_desktops;
  Atom atom_wm_change_state;
  Atom atom_sm_client_id;
  Atom atom_wm_client_leader;
  Atom atom_wm_window_role;
  Atom atom_net_current_desktop;
  Atom atom_net_supporting_wm_check;
  Atom atom_net_supported;
  Atom atom_net_wm_window_type;
  Atom atom_net_wm_window_type_desktop;
  Atom atom_net_wm_window_type_dock;
  Atom atom_net_wm_window_type_toolbar;
  Atom atom_net_wm_window_type_menu;
  Atom atom_net_wm_window_type_dialog;
  Atom atom_net_wm_window_type_normal;
  Atom atom_net_wm_state_modal;
  Atom atom_net_client_list;
  Atom atom_net_client_list_stacking;
  Atom atom_net_wm_state_skip_taskbar;
  Atom atom_net_wm_state_skip_pager;
  Atom atom_win_workspace;
  Atom atom_win_layer;
  Atom atom_win_protocols;
  Atom atom_win_supporting_wm_check;
  Atom atom_net_wm_icon_name;
  Atom atom_net_wm_icon;
  Atom atom_net_wm_icon_geometry;
  Atom atom_utf8_string;
  Atom atom_wm_icon_size;
  Atom atom_kwm_win_icon;
  Atom atom_net_wm_moveresize;
  Atom atom_net_active_window;
  Atom atom_metacity_restart_message;
  Atom atom_net_wm_strut;
  Atom atom_win_hints;
  Atom atom_metacity_reload_theme_message;
  Atom atom_metacity_set_keybindings_message;
  Atom atom_net_wm_state_hidden;
  Atom atom_net_wm_window_type_utility;
  Atom atom_net_wm_window_type_splashscreen;
  Atom atom_net_wm_ping;
  Atom atom_net_wm_pid;
  Atom atom_wm_client_machine;
  Atom atom_net_wm_state_fullscreen;
  Atom atom_net_workarea;
  Atom atom_net_show_desktop;
  Atom atom_net_desktop_layout;
  Atom atom_manager;
  Atom atom_targets;
  Atom atom_multiple;
  Atom atom_timestamp;
  Atom atom_version;
  Atom atom_atom_pair;
  Atom atom_net_desktop_names;
  Atom atom_net_wm_allowed_actions;
  Atom atom_net_wm_action_move;
  Atom atom_net_wm_action_resize;
  Atom atom_net_wm_action_shade;
  Atom atom_net_wm_action_stick;
  Atom atom_net_wm_action_maximize_horz;
  Atom atom_net_wm_action_maximize_vert;
  Atom atom_net_wm_action_change_desktop;
  Atom atom_net_wm_action_close;
  
  /* This is the actual window from focus events,
   * not the one we last set
   */
  MetaWindow *focus_window;

  /* Most recently focused list. Always contains all
   * live windows.
   */
  GList *mru_list;
  
  GList *workspaces;

  guint showing_desktop : 1;
  guint static_gravity_works : 1;
  
  /*< private-ish >*/
  MetaEventQueue *events;
  GSList *screens;
  GHashTable *window_ids;
  int error_traps;
  int (* error_trap_handler) (Display     *display,
                              XErrorEvent *error);  
  int server_grab_count;

  /* This window holds the focus when we don't want to focus
   * any actual clients
   */
  Window no_focus_window;
  
  /* for double click */
  int double_click_time;
  Time last_button_time;
  Window last_button_xwindow;
  int last_button_num;
  guint is_double_click : 1;

  /* serials of leave/unmap events that may
   * correspond to an enter event we should
   * ignore
   */
  unsigned long ignored_serials[N_IGNORED_SERIALS];
  Window ungrab_should_not_cause_focus_window;
  
  guint32 current_time;

  /* Pings which we're waiting for a reply from */
  GSList     *pending_pings;

  /* Pending autoraise */
  guint       autoraise_timeout_id;
  
  /* current window operation */
  MetaGrabOp  grab_op;
  MetaScreen *grab_screen;
  MetaWindow *grab_window;
  Window      grab_xwindow;
  int         grab_button;
  int         grab_root_x;
  int         grab_root_y;
  gulong      grab_mask;
  guint       grab_have_pointer : 1;
  guint       grab_have_keyboard : 1;
  MetaRectangle grab_initial_window_pos;
  MetaResizePopup *grab_resize_popup;


  /* Keybindings stuff */
  MetaKeyBinding *screen_bindings;
  int             n_screen_bindings;
  MetaKeyBinding *window_bindings;
  int             n_window_bindings;
  int min_keycode;
  int max_keycode;
  KeySym *keymap;
  int keysyms_per_keycode;
  XModifierKeymap *modmap;
  unsigned int ignored_modifier_mask;
  unsigned int num_lock_mask;
  unsigned int scroll_lock_mask;
  unsigned int hyper_mask;
  unsigned int super_mask;
  unsigned int meta_mask;
  
  /* Xinerama cache */
  unsigned int xinerama_cache_invalidated : 1;

  /* Closing down the display */
  int closing;
};

gboolean      meta_display_open                (const char  *name);
void          meta_display_close               (MetaDisplay *display);
MetaScreen*   meta_display_screen_for_root     (MetaDisplay *display,
                                                Window       xroot);
MetaScreen*   meta_display_screen_for_x_screen (MetaDisplay *display,
                                                Screen      *screen);
MetaScreen*   meta_display_screen_for_xwindow  (MetaDisplay *display,
                                                Window       xindow);
void          meta_display_grab                (MetaDisplay *display);
void          meta_display_ungrab              (MetaDisplay *display);
gboolean      meta_display_is_double_click     (MetaDisplay *display);

void          meta_display_unmanage_screen     (MetaDisplay *display,
                                                MetaScreen  *screen);

void          meta_display_unmanage_windows_for_screen (MetaDisplay *display,
                                                        MetaScreen  *screen);

/* A given MetaWindow may have various X windows that "belong"
 * to it, such as the frame window.
 */
MetaWindow* meta_display_lookup_x_window     (MetaDisplay *display,
                                              Window       xwindow);
void        meta_display_register_x_window   (MetaDisplay *display,
                                              Window      *xwindowp,
                                              MetaWindow  *window);
void        meta_display_unregister_x_window (MetaDisplay *display,
                                              Window       xwindow);

GSList*     meta_display_list_windows        (MetaDisplay *display);

MetaDisplay* meta_display_for_x_display  (Display     *xdisplay);
GSList*      meta_displays_list          (void);

MetaWorkspace* meta_display_get_workspace_by_index        (MetaDisplay   *display,
                                                           int            index);
MetaWorkspace* meta_display_get_workspace_by_screen_index (MetaDisplay   *display,
                                                           MetaScreen    *screen,
                                                           int            index);

Cursor         meta_display_create_x_cursor (MetaDisplay *display,
                                             MetaCursor   cursor);

gboolean meta_display_begin_grab_op (MetaDisplay *display,
                                     MetaScreen  *screen,
                                     MetaWindow  *window,
                                     MetaGrabOp   op,
                                     gboolean     pointer_already_grabbed,
                                     int          button,
                                     gulong       modmask,
                                     Time         timestamp,
                                     int          root_x,
                                     int          root_y);
void     meta_display_end_grab_op   (MetaDisplay *display,
                                     Time         timestamp);

void     meta_display_grab_window_buttons    (MetaDisplay *display,
                                              Window       xwindow);
void     meta_display_ungrab_window_buttons  (MetaDisplay *display,
                                              Window       xwindow);

void meta_display_grab_focus_window_button   (MetaDisplay *display,
                                              Window       xwindow);
void meta_display_ungrab_focus_window_button (MetaDisplay *display,
                                              Window       xwindow);

/* make a request to ensure the event serial has changed */
void     meta_display_increment_event_serial (MetaDisplay *display);

void     meta_display_update_active_window_hint (MetaDisplay *display);

/* Show/hide the desktop (temporarily hide all windows) */
void     meta_display_show_desktop   (MetaDisplay *display);
void     meta_display_unshow_desktop (MetaDisplay *display);

guint32  meta_display_get_current_time (MetaDisplay *display);

/* utility goo */
const char* meta_event_mode_to_string   (int m);
const char* meta_event_detail_to_string (int d);

void meta_display_queue_retheme_all_windows (MetaDisplay *display);
void meta_display_retheme_all (void);

void     meta_display_ping_window              (MetaDisplay        *display,
						MetaWindow         *window,
						Time                timestamp,
						MetaWindowPingFunc  ping_reply_func,
						MetaWindowPingFunc  ping_timeout_func,
						void               *user_data);
gboolean meta_display_window_has_pending_pings (MetaDisplay        *display,
						MetaWindow         *window);

typedef enum
{
  META_TAB_LIST_NORMAL,
  META_TAB_LIST_DOCKS
  

} MetaTabList;

GSList* meta_display_get_tab_list (MetaDisplay   *display,
                                   MetaTabList    type,
                                   MetaScreen    *screen,
                                   MetaWorkspace *workspace);

MetaWindow* meta_display_get_tab_next (MetaDisplay   *display,
                                       MetaTabList    type,
				       MetaScreen    *screen,
                                       MetaWorkspace *workspace,
                                       MetaWindow    *window,
                                       gboolean       backward);

int meta_resize_gravity_from_grab_op (MetaGrabOp op);

gboolean meta_rectangle_intersect (MetaRectangle *src1,
                                   MetaRectangle *src2,
                                   MetaRectangle *dest);

#endif