display.h 15.8 KB
Newer Older
rhp's avatar
...  
rhp committed
1
2
3
4
/* Metacity X display handler */

/* 
 * Copyright (C) 2001 Havoc Pennington
5
 * Copyright (C) 2002 Red Hat, Inc.
6
 * Copyright (C) 2003 Rob Adams
rhp's avatar
...  
rhp committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * 
 * 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

Havoc Pennington's avatar
Havoc Pennington committed
27
28
29
30
#ifndef PACKAGE
#error "config.h not included"
#endif

rhp's avatar
...  
rhp committed
31
#include <glib.h>
rhp's avatar
...    
rhp committed
32
#include <X11/Xlib.h>
rhp's avatar
...  
rhp committed
33
#include "eventqueue.h"
rhp's avatar
...    
rhp committed
34
#include "common.h"
rhp's avatar
...  
rhp committed
35

36
37
38
39
#ifdef HAVE_STARTUP_NOTIFICATION
#include <libsn/sn.h>
#endif

40
41
42
43
#ifdef HAVE_XSYNC
#include <X11/extensions/sync.h>
#endif

Havoc Pennington's avatar
Havoc Pennington committed
44
45
#define meta_XFree(p) do { if ((p)) XFree ((p)); } while (0)

rhp's avatar
...    
rhp committed
46
47
48
49
50
51
52
53
54
55
56
/* this doesn't really belong here, oh well. */
typedef struct _MetaRectangle MetaRectangle;

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

Havoc Pennington's avatar
Havoc Pennington committed
57
typedef struct MetaCompositor  MetaCompositor;
58
59
60
61
62
63
64
65
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;
rhp's avatar
...  
rhp committed
66

67
typedef struct _MetaWindowPropHooks MetaWindowPropHooks;
Havoc Pennington's avatar
Havoc Pennington committed
68
typedef struct _MetaGroupPropHooks  MetaGroupPropHooks;
69

70
71
typedef void (* MetaWindowPingFunc) (MetaDisplay *display,
				     Window       xwindow,
72
				     Time         timestamp,
73
74
75
				     gpointer     user_data);


rhp's avatar
...    
rhp committed
76
77
78
79
#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  */

80
81
82
83
84
85
86
/* 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

rhp's avatar
...  
rhp committed
87
88
89
90
struct _MetaDisplay
{
  char *name;
  Display *xdisplay;
rhp's avatar
...    
rhp committed
91

rhp's avatar
...    
rhp committed
92
93
  Window leader_window;
  
rhp's avatar
...    
rhp committed
94
  Atom atom_net_wm_name;
rhp's avatar
...    
rhp committed
95
96
97
  Atom atom_wm_protocols;
  Atom atom_wm_take_focus;
  Atom atom_wm_delete_window;
rhp's avatar
...    
rhp committed
98
  Atom atom_wm_state;
rhp's avatar
...    
rhp committed
99
  Atom atom_net_close_window;
rhp's avatar
...    
rhp committed
100
101
102
103
104
  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;
rhp's avatar
rhp committed
105
106
  Atom atom_net_wm_desktop;
  Atom atom_net_number_of_desktops;
rhp's avatar
...    
rhp committed
107
108
109
110
  Atom atom_wm_change_state;
  Atom atom_sm_client_id;
  Atom atom_wm_client_leader;
  Atom atom_wm_window_role;
rhp's avatar
...    
rhp committed
111
112
  Atom atom_net_current_desktop;
  Atom atom_net_supporting_wm_check;
113
  Atom atom_net_supported;
rhp's avatar
...    
rhp committed
114
115
116
117
118
119
120
121
  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;
rhp's avatar
...    
rhp committed
122
123
  Atom atom_net_client_list;
  Atom atom_net_client_list_stacking;
rhp's avatar
...    
rhp committed
124
125
  Atom atom_net_wm_state_skip_taskbar;
  Atom atom_net_wm_state_skip_pager;
rhp's avatar
...    
rhp committed
126
127
  Atom atom_net_wm_icon_name;
  Atom atom_net_wm_icon;
128
  Atom atom_net_wm_icon_geometry;
129
  Atom atom_utf8_string;
Havoc Pennington's avatar
Havoc Pennington committed
130
  Atom atom_wm_icon_size;
131
  Atom atom_kwm_win_icon;
132
  Atom atom_net_wm_moveresize;
Havoc Pennington's avatar
Havoc Pennington committed
133
  Atom atom_net_active_window;
134
  Atom atom_metacity_restart_message;
135
  Atom atom_net_wm_strut;
136
  Atom atom_metacity_reload_theme_message;
137
  Atom atom_metacity_set_keybindings_message;
138
  Atom atom_net_wm_state_hidden;
139
  Atom atom_net_wm_window_type_utility;
Havoc Pennington's avatar
Havoc Pennington committed
140
  Atom atom_net_wm_window_type_splash;
141
142
143
  Atom atom_net_wm_ping;
  Atom atom_net_wm_pid;
  Atom atom_wm_client_machine;
144
  Atom atom_net_wm_state_fullscreen;
145
  Atom atom_net_workarea;
146
  Atom atom_net_showing_desktop;
147
  Atom atom_net_desktop_layout;
Havoc Pennington's avatar
Havoc Pennington committed
148
149
150
151
152
153
  Atom atom_manager;
  Atom atom_targets;
  Atom atom_multiple;
  Atom atom_timestamp;
  Atom atom_version;
  Atom atom_atom_pair;
Havoc Pennington's avatar
Havoc Pennington committed
154
  Atom atom_net_desktop_names;
155
156
157
  Atom atom_net_wm_allowed_actions;
  Atom atom_net_wm_action_move;
  Atom atom_net_wm_action_resize;
158
159
  Atom atom_net_wm_action_fullscreen;
  Atom atom_net_wm_action_minimize;
160
161
162
163
164
165
  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;
Havoc Pennington's avatar
Havoc Pennington committed
166
167
  Atom atom_net_wm_state_above;
  Atom atom_net_wm_state_below;
Havoc Pennington's avatar
Havoc Pennington committed
168
  Atom atom_net_startup_id;
169
  Atom atom_metacity_toggle_verbose;
170
171
  Atom atom_net_wm_sync_request;
  Atom atom_net_wm_sync_request_counter;
172
173
174
  Atom atom_gnome_panel_action;
  Atom atom_gnome_panel_action_main_menu;
  Atom atom_gnome_panel_action_run_dialog;
175
  Atom atom_metacity_sentinel;
176
  Atom atom_net_wm_strut_partial;
177
178
  Atom atom_net_frame_extents;
  Atom atom_net_request_frame_extents;
179
  Atom atom_net_wm_user_time;
180
181
182
183
184
  Atom atom_net_wm_state_demands_attention;
  Atom atom_net_restack_window;
  Atom atom_net_moveresize_window;
  Atom atom_net_desktop_geometry;
  Atom atom_net_desktop_viewport;
185

rhp's avatar
...    
rhp committed
186
187
188
189
  /* This is the actual window from focus events,
   * not the one we last set
   */
  MetaWindow *focus_window;
rhp's avatar
...    
rhp committed
190

191
  /* window we are expecting a FocusIn event for
192
193
194
   */
  MetaWindow *expected_focus_window;

195
  guint static_gravity_works : 1;
rhp's avatar
...    
rhp committed
196
  
rhp's avatar
...    
rhp committed
197
  /*< private-ish >*/
198
  guint error_trap_synced_at_last_pop : 1;
rhp's avatar
...  
rhp committed
199
200
201
  MetaEventQueue *events;
  GSList *screens;
  GHashTable *window_ids;
202
203
204
  int error_traps;
  int (* error_trap_handler) (Display     *display,
                              XErrorEvent *error);  
rhp's avatar
...    
rhp committed
205
  int server_grab_count;
rhp's avatar
...    
rhp committed
206

207
208
209
210
211
  /* This window holds the focus when we don't want to focus
   * any actual clients
   */
  Window no_focus_window;
  
rhp's avatar
...    
rhp committed
212
213
214
215
216
  /* for double click */
  Time last_button_time;
  Window last_button_xwindow;
  int last_button_num;
  guint is_double_click : 1;
217

218
219
220
221
222
223
224
  /* 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;
  
225
  guint32 current_time;
226
227
228

  /* Pings which we're waiting for a reply from */
  GSList     *pending_pings;
Havoc Pennington's avatar
Havoc Pennington committed
229
230
231

  /* Pending autoraise */
  guint       autoraise_timeout_id;
232
233
234

  /* Alt+click button grabs */
  unsigned int window_grab_modifiers;
rhp's avatar
...    
rhp committed
235
  
rhp's avatar
...    
rhp committed
236
237
  /* current window operation */
  MetaGrabOp  grab_op;
238
  MetaScreen *grab_screen;
rhp's avatar
...    
rhp committed
239
  MetaWindow *grab_window;
240
  Window      grab_xwindow;
241
  gulong      grab_start_serial;
rhp's avatar
...    
rhp committed
242
  int         grab_button;
243
244
245
  int         grab_anchor_root_x;
  int         grab_anchor_root_y;
  MetaRectangle grab_anchor_window_pos;
246
247
  int         grab_latest_motion_x;
  int         grab_latest_motion_y;
rhp's avatar
...    
rhp committed
248
249
250
  gulong      grab_mask;
  guint       grab_have_pointer : 1;
  guint       grab_have_keyboard : 1;
251
252
253
  guint       grab_wireframe_active : 1;
  guint       grab_was_cancelled : 1;
  MetaRectangle grab_wireframe_rect;
254
  MetaRectangle grab_wireframe_last_xor_rect;
rhp's avatar
...    
rhp committed
255
  MetaRectangle grab_initial_window_pos;
256
  MetaResizePopup *grab_resize_popup;
257
  GTimeVal    grab_last_moveresize_time;
258
  Time        grab_motion_notify_time;
259
  
260
261
262
263
264
  /* we use property updates as sentinels for certain window focus events
   * to avoid some race conditions on EnterNotify events
   */
  int         sentinel_counter;

265
266
267
#ifdef HAVE_XKB
  int         xkb_base_event_type;
#endif
268
#ifdef HAVE_XSYNC
269
270
  /* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
  XSyncAlarm  grab_sync_request_alarm;
271
#endif
272
  int	      grab_resize_timeout_id;
273
274
275
276
277
278

  /* Keybindings stuff */
  MetaKeyBinding *screen_bindings;
  int             n_screen_bindings;
  MetaKeyBinding *window_bindings;
  int             n_window_bindings;
279
280
  unsigned int min_keycode;
  unsigned int max_keycode;
281
282
283
284
285
286
  KeySym *keymap;
  int keysyms_per_keycode;
  XModifierKeymap *modmap;
  unsigned int ignored_modifier_mask;
  unsigned int num_lock_mask;
  unsigned int scroll_lock_mask;
287
288
289
290
  unsigned int hyper_mask;
  unsigned int super_mask;
  unsigned int meta_mask;
  
Havoc Pennington's avatar
Havoc Pennington committed
291
292
  /* Xinerama cache */
  unsigned int xinerama_cache_invalidated : 1;
293
294
295

  /* Closing down the display */
  int closing;
296
297
298

  /* Managed by group.c */
  GHashTable *groups_by_leader;
Havoc Pennington's avatar
Havoc Pennington committed
299

300
301
302
  /* currently-active window menu if any */
  MetaWindowMenu *window_menu;
  MetaWindow *window_with_menu;
303
304
305

  /* Managed by window-props.c */
  MetaWindowPropHooks *prop_hooks;
Havoc Pennington's avatar
Havoc Pennington committed
306
307
308

  /* Managed by group-props.c */
  MetaGroupPropHooks *group_prop_hooks;
Havoc Pennington's avatar
Havoc Pennington committed
309
310
311

  /* Managed by compositor.c */
  MetaCompositor *compositor;
Havoc Pennington's avatar
Havoc Pennington committed
312
313
314
315
  
#ifdef HAVE_STARTUP_NOTIFICATION
  SnDisplay *sn_display;
#endif
316
317
318
319
#ifdef HAVE_XSYNC
  int xsync_event_base;
  int xsync_error_base;
#endif
320
321
322
#ifdef HAVE_SHAPE
  int shape_event_base;
  int shape_error_base;
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#endif
#ifdef HAVE_RENDER
  int render_event_base;
  int render_error_base;
#endif
#ifdef HAVE_XSYNC
  unsigned int have_xsync : 1;
#define META_DISPLAY_HAS_XSYNC(display) ((display)->have_xsync)
#else
#define META_DISPLAY_HAS_XSYNC(display) FALSE
#endif
#ifdef HAVE_SHAPE
  unsigned int have_shape : 1;
#define META_DISPLAY_HAS_SHAPE(display) ((display)->have_shape)
337
338
339
#else
#define META_DISPLAY_HAS_SHAPE(display) FALSE
#endif
340
341
342
343
344
345
#ifdef HAVE_RENDER
  unsigned int have_render : 1;
#define META_DISPLAY_HAS_RENDER(display) ((display)->have_render)
#else
#define META_DISPLAY_HAS_RENDER(display) FALSE
#endif
rhp's avatar
...  
rhp committed
346
347
};

rhp's avatar
...    
rhp committed
348
349
350
351
352
353
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);
354
355
MetaScreen*   meta_display_screen_for_xwindow  (MetaDisplay *display,
                                                Window       xindow);
rhp's avatar
...    
rhp committed
356
357
void          meta_display_grab                (MetaDisplay *display);
void          meta_display_ungrab              (MetaDisplay *display);
rhp's avatar
...    
rhp committed
358
gboolean      meta_display_is_double_click     (MetaDisplay *display);
rhp's avatar
...    
rhp committed
359

Havoc Pennington's avatar
Havoc Pennington committed
360
361
362
363
364
365
void          meta_display_unmanage_screen     (MetaDisplay *display,
                                                MetaScreen  *screen);

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

rhp's avatar
...    
rhp committed
366
367
368
369
370
371
372
373
374
375
376
/* 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);

rhp's avatar
...    
rhp committed
377
GSList*     meta_display_list_windows        (MetaDisplay *display);
rhp's avatar
...  
rhp committed
378

rhp's avatar
...    
rhp committed
379
MetaDisplay* meta_display_for_x_display  (Display     *xdisplay);
rhp's avatar
...    
rhp committed
380
GSList*      meta_displays_list          (void);
rhp's avatar
...  
rhp committed
381

rhp's avatar
...    
rhp committed
382
383
384
Cursor         meta_display_create_x_cursor (MetaDisplay *display,
                                             MetaCursor   cursor);

385
void     meta_display_set_grab_op_cursor (MetaDisplay *display,
386
                                          MetaScreen  *screen,
387
388
389
390
391
                                          MetaGrabOp   op,
                                          gboolean     change_pointer,
                                          Window       grab_xwindow,
                                          Time         timestamp);

rhp's avatar
...    
rhp committed
392
gboolean meta_display_begin_grab_op (MetaDisplay *display,
393
                                     MetaScreen  *screen,
rhp's avatar
...    
rhp committed
394
395
396
                                     MetaWindow  *window,
                                     MetaGrabOp   op,
                                     gboolean     pointer_already_grabbed,
397
                                     int          event_serial,
rhp's avatar
...    
rhp committed
398
399
400
401
402
403
404
405
                                     int          button,
                                     gulong       modmask,
                                     Time         timestamp,
                                     int          root_x,
                                     int          root_y);
void     meta_display_end_grab_op   (MetaDisplay *display,
                                     Time         timestamp);

rhp's avatar
...    
rhp committed
406
407
408
409
void     meta_display_grab_window_buttons    (MetaDisplay *display,
                                              Window       xwindow);
void     meta_display_ungrab_window_buttons  (MetaDisplay *display,
                                              Window       xwindow);
rhp's avatar
...    
rhp committed
410

411
void meta_display_grab_focus_window_button   (MetaDisplay *display,
412
                                              MetaWindow  *window);
413
void meta_display_ungrab_focus_window_button (MetaDisplay *display,
414
                                              MetaWindow  *window);
415

416
417
/* make a request to ensure the event serial has changed */
void     meta_display_increment_event_serial (MetaDisplay *display);
rhp's avatar
...    
rhp committed
418

Havoc Pennington's avatar
Havoc Pennington committed
419
420
void     meta_display_update_active_window_hint (MetaDisplay *display);

421
422
guint32  meta_display_get_current_time (MetaDisplay *display);

423
/* utility goo */
424
425
const char* meta_event_mode_to_string   (int m);
const char* meta_event_detail_to_string (int d);
426

427
428
429
void meta_display_queue_retheme_all_windows (MetaDisplay *display);
void meta_display_retheme_all (void);

430
431
432
433
434
435
436
437
438
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);

Havoc Pennington's avatar
Havoc Pennington committed
439
440
441
442
443
444
445
446
typedef enum
{
  META_TAB_LIST_NORMAL,
  META_TAB_LIST_DOCKS
  

} MetaTabList;

447
448
449
450
GList* meta_display_get_tab_list (MetaDisplay   *display,
                                  MetaTabList    type,
                                  MetaScreen    *screen,
                                  MetaWorkspace *workspace);
Havoc Pennington's avatar
Havoc Pennington committed
451
452

MetaWindow* meta_display_get_tab_next (MetaDisplay   *display,
Havoc Pennington's avatar
Havoc Pennington committed
453
                                       MetaTabList    type,
454
				       MetaScreen    *screen,
Havoc Pennington's avatar
Havoc Pennington committed
455
456
457
                                       MetaWorkspace *workspace,
                                       MetaWindow    *window,
                                       gboolean       backward);
458

Havoc Pennington's avatar
Havoc Pennington committed
459
460
461
462
463
MetaWindow* meta_display_get_tab_current (MetaDisplay   *display,
                                          MetaTabList    type,
                                          MetaScreen    *screen,
                                          MetaWorkspace *workspace);

464
465
int meta_resize_gravity_from_grab_op (MetaGrabOp op);

466
467
468
gboolean meta_grab_op_is_moving   (MetaGrabOp op);
gboolean meta_grab_op_is_resizing (MetaGrabOp op);

469
470
471
gboolean meta_rectangle_intersect (MetaRectangle *src1,
                                   MetaRectangle *src2,
                                   MetaRectangle *dest);
472
473
gboolean meta_rectangle_equal (const MetaRectangle *src1,
                               const MetaRectangle *src2);
474

475
476
477
478
void meta_display_devirtualize_modifiers (MetaDisplay        *display,
                                          MetaVirtualModifier modifiers,
                                          unsigned int       *mask);

479
480
481
482
void meta_display_increment_focus_sentinel (MetaDisplay *display);
void meta_display_decrement_focus_sentinel (MetaDisplay *display);
gboolean meta_display_focus_sentinel_clear (MetaDisplay *display);

rhp's avatar
...  
rhp committed
483
#endif