display-private.h 16.4 KB
Newer Older
1
2
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

3
/* Mutter X display handler */
rhp's avatar
...  
rhp committed
4

Jasper St. Pierre's avatar
Jasper St. Pierre committed
5
/*
rhp's avatar
...  
rhp committed
6
 * Copyright (C) 2001 Havoc Pennington
7
 * Copyright (C) 2002 Red Hat, Inc.
8
 * Copyright (C) 2003 Rob Adams
9
 * Copyright (C) 2004-2006 Elijah Newren
Jasper St. Pierre's avatar
Jasper St. Pierre committed
10
 *
rhp's avatar
...  
rhp committed
11
12
13
14
15
16
17
18
19
 * 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.
Jasper St. Pierre's avatar
Jasper St. Pierre committed
20
 *
rhp's avatar
...  
rhp committed
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
rhp's avatar
...  
rhp committed
23
24
 */

25
26
#ifndef META_DISPLAY_PRIVATE_H
#define META_DISPLAY_PRIVATE_H
rhp's avatar
...  
rhp committed
27

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

rhp's avatar
...  
rhp committed
32
#include <glib.h>
rhp's avatar
...    
rhp committed
33
#include <X11/Xlib.h>
34
35
36
#include <meta/common.h>
#include <meta/boxes.h>
#include <meta/display.h>
37
#include "keybindings-private.h"
38
#include "meta-gesture-tracker-private.h"
39
#include <meta/prefs.h>
40
#include <meta/barrier.h>
41
#include <clutter/clutter.h>
rhp's avatar
...  
rhp committed
42

43
44
45
46
#ifdef HAVE_STARTUP_NOTIFICATION
#include <libsn/sn.h>
#endif

47
48
#include <X11/extensions/sync.h>

49
50
typedef struct _MetaStack      MetaStack;
typedef struct _MetaUISlave    MetaUISlave;
rhp's avatar
...  
rhp committed
51

Havoc Pennington's avatar
Havoc Pennington committed
52
typedef struct _MetaGroupPropHooks  MetaGroupPropHooks;
53
typedef struct _MetaWindowPropHooks MetaWindowPropHooks;
54

55
56
typedef struct MetaEdgeResistanceData MetaEdgeResistanceData;

57
58
59
60
typedef enum {
  META_LIST_DEFAULT                   = 0,      /* normal windows */
  META_LIST_INCLUDE_OVERRIDE_REDIRECT = 1 << 0, /* normal and O-R */
} MetaListWindowsFlags;
61

rhp's avatar
...    
rhp committed
62
63
64
65
#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  */

66
67
68
/* 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,
69
70
71
 * and the LeaveNotify/EnterNotify from the pointer ungrab. It
 * also has to be big enough to hold ignored serials from the point
 * where we reshape the stage to the point where we get events back.
72
 */
73
#define N_IGNORED_CROSSING_SERIALS  10
74

75
76
77
78
79
80
81
typedef enum {
  META_TILE_NONE,
  META_TILE_LEFT,
  META_TILE_RIGHT,
  META_TILE_MAXIMIZED
} MetaTileMode;

rhp's avatar
...  
rhp committed
82
83
struct _MetaDisplay
{
84
  GObject parent_instance;
Jasper St. Pierre's avatar
Jasper St. Pierre committed
85

rhp's avatar
...  
rhp committed
86
87
  char *name;
  Display *xdisplay;
rhp's avatar
...    
rhp committed
88

89
90
  int clutter_event_filter;

rhp's avatar
...    
rhp committed
91
  Window leader_window;
92
  Window timestamp_pinging_window;
Colin Walters's avatar
Colin Walters committed
93

94
95
96
97
  /* Pull in all the names of atoms as fields; we will intern them when the
   * class is constructed.
   */
#define item(x)  Atom atom_##x;
98
#include <meta/atomnames.h>
99
#undef item
100

101
102
103
104
105
106
107
108
  /* The window and serial of the most recent FocusIn event. */
  Window server_focus_window;
  gulong server_focus_serial;

  /* Our best guess as to the "currently" focused window (that is, the
   * window that we expect will be focused at the point when the X
   * server processes our next request), and the serial of the request
   * or event that caused this.
rhp's avatar
...    
rhp committed
109
110
   */
  MetaWindow *focus_window;
111
112
113
  /* For windows we've focused that don't necessarily have an X window,
   * like the no_focus_window or the stage X window. */
  Window focus_xwindow;
114
  gulong focus_serial;
115

116
  /* last timestamp passed to XSetInputFocus */
117
  guint32 last_focus_time;
118

119
  /* last user interaction time in any app */
120
  guint32 last_user_time;
121

122
123
124
125
126
  /* whether we're using mousenav (only relevant for sloppy&mouse focus modes;
   * !mouse_mode means "keynav mode")
   */
  guint mouse_mode : 1;

127
128
129
130
131
132
  /* Helper var used when focus_new_windows setting is 'strict'; only
   * relevant in 'strict' mode and if the focus window is a terminal.
   * In that case, we don't allow new windows to take focus away from
   * a terminal, but if the user explicitly did something that should
   * allow a different window to gain focus (e.g. global keybinding or
   * clicking on a dock), then we will allow the transfer.
133
134
135
   */
  guint allow_terminal_deactivation : 1;

136
137
138
139
140
141
142
  /* If true, server->focus_serial refers to us changing the focus; in
   * this case, we can ignore focus events that have exactly focus_serial,
   * since we take care to make another request immediately afterwards.
   * But if focus is being changed by another client, we have to accept
   * multiple events with the same serial.
   */
  guint focused_by_us : 1;
Jasper St. Pierre's avatar
Jasper St. Pierre committed
143

rhp's avatar
...    
rhp committed
144
  /*< private-ish >*/
145
  MetaScreen *screen;
146
  GHashTable *xids;
147
  GHashTable *wayland_windows;
148

149
150
151
152
  /* serials of leave/unmap events that may
   * correspond to an enter event we should
   * ignore
   */
153
  unsigned long ignored_crossing_serials[N_IGNORED_CROSSING_SERIALS];
154
  Window ungrab_should_not_cause_focus_window;
Jasper St. Pierre's avatar
Jasper St. Pierre committed
155

156
  guint32 current_time;
157

158
159
160
161
162
163
164
165
166
  /* We maintain a sequence counter, incremented for each #MetaWindow
   * created.  This is exposed by meta_window_get_stable_sequence()
   * but is otherwise not used inside mutter.
   *
   * It can be useful to plugins which want to sort windows in a
   * stable fashion.
   */
  guint32 window_sequence_counter;

167
  /* Pings which we're waiting for a reply from */
168
  GSList     *pending_pings;
Havoc Pennington's avatar
Havoc Pennington committed
169

170
171
172
  /* Pending focus change */
  guint       focus_timeout_id;

Havoc Pennington's avatar
Havoc Pennington committed
173
174
  /* Pending autoraise */
  guint       autoraise_timeout_id;
175
  MetaWindow* autoraise_window;
176
177

  /* Alt+click button grabs */
178
  ClutterModifierType window_grab_modifiers;
Jasper St. Pierre's avatar
Jasper St. Pierre committed
179

rhp's avatar
...    
rhp committed
180
181
182
183
  /* current window operation */
  MetaGrabOp  grab_op;
  MetaWindow *grab_window;
  int         grab_button;
184
185
186
  int         grab_anchor_root_x;
  int         grab_anchor_root_y;
  MetaRectangle grab_anchor_window_pos;
187
  MetaTileMode  grab_tile_mode;
188
  int           grab_tile_monitor_number;
189
190
  int         grab_latest_motion_x;
  int         grab_latest_motion_y;
rhp's avatar
...    
rhp committed
191
192
  guint       grab_have_pointer : 1;
  guint       grab_have_keyboard : 1;
193
  guint       grab_frame_action : 1;
194
195
196
  /* During a resize operation, the directions in which we've broken
   * out of the initial maximization state */
  guint       grab_resize_unmaximize : 2; /* MetaMaximizeFlags */
rhp's avatar
...    
rhp committed
197
  MetaRectangle grab_initial_window_pos;
198
199
  int         grab_initial_x, grab_initial_y;  /* These are only relevant for */
  gboolean    grab_threshold_movement_reached; /* raise_on_click == FALSE.    */
200
  GTimeVal    grab_last_moveresize_time;
201
  MetaEdgeResistanceData *grab_edge_resistance_data;
202
  unsigned int grab_last_user_action_was_snap;
203
  guint32     grab_timestamp;
204

205
206
207
208
209
  /* we use property updates as sentinels for certain window focus events
   * to avoid some race conditions on EnterNotify events
   */
  int         sentinel_counter;

210
211
#ifdef HAVE_XKB
  int         xkb_base_event_type;
212
  guint32     last_bell_time;
213
#endif
214
  int	      grab_resize_timeout_id;
215
216

  /* Keybindings stuff */
217
218
  GHashTable     *key_bindings;
  GHashTable     *key_bindings_index;
Björn Lindqvist's avatar
Björn Lindqvist committed
219
220
  int             min_keycode;
  int             max_keycode;
221
222
223
  KeySym *keymap;
  int keysyms_per_keycode;
  unsigned int ignored_modifier_mask;
224
225
226
  unsigned int hyper_mask;
  unsigned int super_mask;
  unsigned int meta_mask;
227
228
  MetaKeyCombo overlay_key_combo;
  gboolean overlay_key_only_pressed;
229
230
  MetaKeyCombo *iso_next_group_combos;
  int n_iso_next_group_combos;
Jasper St. Pierre's avatar
Jasper St. Pierre committed
231

232
233
  /* Monitor cache */
  unsigned int monitor_cache_invalidated : 1;
234

235
236
237
  /* Opening the display */
  unsigned int display_opening : 1;

238
239
  /* Closing down the display */
  int closing;
240
241
242

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

244
  /* Managed by window-props.c */
245
  MetaWindowPropHooks *prop_hooks_table;
246
  GHashTable *prop_hooks;
247
  int n_prop_hooks;
Havoc Pennington's avatar
Havoc Pennington committed
248
249
250

  /* Managed by group-props.c */
  MetaGroupPropHooks *group_prop_hooks;
Havoc Pennington's avatar
Havoc Pennington committed
251
252
253

  /* Managed by compositor.c */
  MetaCompositor *compositor;
254

255
  MetaGestureTracker *gesture_tracker;
256
  ClutterEventSequence *pointer_emulating_sequence;
257

258
259
260
261
262
263
264
265
  int composite_event_base;
  int composite_error_base;
  int composite_major_version;
  int composite_minor_version;
  int damage_event_base;
  int damage_error_base;
  int xfixes_event_base;
  int xfixes_error_base;
266
267
268
269
  int xinput_error_base;
  int xinput_event_base;
  int xinput_opcode;

Havoc Pennington's avatar
Havoc Pennington committed
270
271
272
#ifdef HAVE_STARTUP_NOTIFICATION
  SnDisplay *sn_display;
#endif
273
274
  int xsync_event_base;
  int xsync_error_base;
275
276
  int shape_event_base;
  int shape_error_base;
277
278
279
280
  unsigned int have_xsync : 1;
#define META_DISPLAY_HAS_XSYNC(display) ((display)->have_xsync)
  unsigned int have_shape : 1;
#define META_DISPLAY_HAS_SHAPE(display) ((display)->have_shape)
Iain Holmes's avatar
Iain Holmes committed
281
282
283
284
  unsigned int have_composite : 1;
  unsigned int have_damage : 1;
#define META_DISPLAY_HAS_COMPOSITE(display) ((display)->have_composite)
#define META_DISPLAY_HAS_DAMAGE(display) ((display)->have_damage)
285
286
287
288
289
290
#ifdef HAVE_XI23
  gboolean have_xinput_23 : 1;
#define META_DISPLAY_HAS_XINPUT_23(display) ((display)->have_xinput_23)
#else
#define META_DISPLAY_HAS_XINPUT_23(display) FALSE
#endif /* HAVE_XI23 */
rhp's avatar
...  
rhp committed
291
292
};

293
294
295
296
297
struct _MetaDisplayClass
{
  GObjectClass parent_class;
};

298
#define XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) \
299
300
  ( (( (time1) < (time2) ) && ( (time2) - (time1) < ((guint32)-1)/2 )) ||     \
    (( (time1) > (time2) ) && ( (time1) - (time2) > ((guint32)-1)/2 ))        \
301
  )
302
303
304
305
306
/**
 * XSERVER_TIME_IS_BEFORE:
 *
 * See the docs for meta_display_xserver_time_is_before().
 */
307
#define XSERVER_TIME_IS_BEFORE(time1, time2)                          \
308
  ( (time1) == 0 ||                                                     \
309
    (XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) && \
310
     (time2) != 0)                                                      \
311
312
  )

313
gboolean      meta_display_open                (void);
314
315
void          meta_display_close               (MetaDisplay *display,
                                                guint32      timestamp);
rhp's avatar
...    
rhp committed
316

Havoc Pennington's avatar
Havoc Pennington committed
317
void          meta_display_unmanage_windows_for_screen (MetaDisplay *display,
318
319
                                                        MetaScreen  *screen,
                                                        guint32      timestamp);
Havoc Pennington's avatar
Havoc Pennington committed
320

321
322
323
324
/* Utility function to compare the stacking of two windows */
int           meta_display_stack_cmp           (const void *a,
                                                const void *b);

rhp's avatar
...    
rhp committed
325
326
327
328
329
330
331
332
333
334
335
/* 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);

336
337
338
339
340
void        meta_display_register_wayland_window   (MetaDisplay *display,
                                                    MetaWindow  *window);
void        meta_display_unregister_wayland_window (MetaDisplay *display,
                                                    MetaWindow  *window);

341
342
343
344
345
346
347
348
MetaWindow* meta_display_lookup_sync_alarm     (MetaDisplay *display,
                                                XSyncAlarm   alarm);
void        meta_display_register_sync_alarm   (MetaDisplay *display,
                                                XSyncAlarm  *alarmp,
                                                MetaWindow  *window);
void        meta_display_unregister_sync_alarm (MetaDisplay *display,
                                                XSyncAlarm   alarm);

349
350
351
void        meta_display_notify_window_created (MetaDisplay  *display,
                                                MetaWindow   *window);

352
353
GSList*     meta_display_list_windows        (MetaDisplay          *display,
                                              MetaListWindowsFlags  flags);
rhp's avatar
...  
rhp committed
354

rhp's avatar
...    
rhp committed
355
MetaDisplay* meta_display_for_x_display  (Display     *xdisplay);
356
MetaDisplay* meta_get_display            (void);
rhp's avatar
...  
rhp committed
357

rhp's avatar
...    
rhp committed
358
359
360
Cursor         meta_display_create_x_cursor (MetaDisplay *display,
                                             MetaCursor   cursor);

361
void     meta_display_update_cursor (MetaDisplay *display);
362

363
364
365
void    meta_display_check_threshold_reached (MetaDisplay *display,
                                              int          x,
                                              int          y);
rhp's avatar
...    
rhp committed
366
367
368
369
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
370

371
void meta_display_grab_focus_window_button   (MetaDisplay *display,
372
                                              MetaWindow  *window);
373
void meta_display_ungrab_focus_window_button (MetaDisplay *display,
374
                                              MetaWindow  *window);
375

376
377
/* Next function is defined in edge-resistance.c */
void meta_display_cleanup_edges              (MetaDisplay *display);
378

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

Havoc Pennington's avatar
Havoc Pennington committed
382
383
void     meta_display_update_active_window_hint (MetaDisplay *display);

384
/* utility goo */
385
386
const char* meta_event_mode_to_string   (int m);
const char* meta_event_detail_to_string (int d);
387

388
389
390
void meta_display_queue_retheme_all_windows (MetaDisplay *display);
void meta_display_retheme_all (void);

Jasper St. Pierre's avatar
Jasper St. Pierre committed
391
392
393
394
void meta_display_ping_window      (MetaWindow  *window,
                                    guint32      serial);
void meta_display_pong_for_serial  (MetaDisplay *display,
                                    guint32      serial);
395

396
397
int meta_resize_gravity_from_grab_op (MetaGrabOp op);

398
399
gboolean meta_grab_op_is_moving   (MetaGrabOp op);
gboolean meta_grab_op_is_resizing (MetaGrabOp op);
400
gboolean meta_grab_op_is_moving_or_resizing (MetaGrabOp op);
401
gboolean meta_grab_op_is_mouse    (MetaGrabOp op);
402
gboolean meta_grab_op_is_keyboard (MetaGrabOp op);
403
gboolean meta_grab_op_should_block_wayland (MetaGrabOp op);
404

405
406
407
408
void meta_display_devirtualize_modifiers (MetaDisplay        *display,
                                          MetaVirtualModifier modifiers,
                                          unsigned int       *mask);

409
410
411
412
void meta_display_increment_focus_sentinel (MetaDisplay *display);
void meta_display_decrement_focus_sentinel (MetaDisplay *display);
gboolean meta_display_focus_sentinel_clear (MetaDisplay *display);

413
414
415
416
void meta_display_queue_autoraise_callback  (MetaDisplay *display,
                                             MetaWindow  *window);
void meta_display_remove_autoraise_callback (MetaDisplay *display);

417
void meta_display_overlay_key_activate (MetaDisplay *display);
418
419
420
void meta_display_accelerator_activate (MetaDisplay     *display,
                                        guint            action,
                                        ClutterKeyEvent *event);
421
gboolean meta_display_modifiers_accelerator_activate (MetaDisplay *display);
422

423
#ifdef HAVE_XI23
424
425
gboolean meta_display_process_barrier_event (MetaDisplay *display,
                                             XIEvent     *event);
426
427
#endif /* HAVE_XI23 */

428
429
430
431
void meta_display_set_input_focus_xwindow (MetaDisplay *display,
                                           MetaScreen  *screen,
                                           Window       window,
                                           guint32      timestamp);
432

433
void meta_display_sync_wayland_input_focus (MetaDisplay *display);
434
435
436
437
438
439
440
441
void meta_display_update_focus_window (MetaDisplay *display,
                                       MetaWindow  *window,
                                       Window       xwindow,
                                       gulong       serial,
                                       gboolean     focused_by_us);

void meta_display_sanity_check_timestamps (MetaDisplay *display,
                                           guint32      timestamp);
442
443
gboolean meta_display_timestamp_too_old (MetaDisplay *display,
                                         guint32     *timestamp);
444

445
446
447
void meta_display_remove_pending_pings_for_window (MetaDisplay *display,
                                                   MetaWindow  *window);

448
449
MetaGestureTracker * meta_display_get_gesture_tracker (MetaDisplay *display);

450
451
452
453
454
455
456
gboolean meta_display_show_restart_message (MetaDisplay *display,
                                            const char  *message);
gboolean meta_display_request_restart      (MetaDisplay *display);

void meta_restart_init (void);
void meta_restart_finish (void);

457
458
void meta_display_cancel_touch (MetaDisplay *display);

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