summaryrefslogtreecommitdiff
path: root/src/core/display-private.h
blob: 62be08ceec02e76dc19fea370d1e49891e189b5f (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/* Marco X display handler */

/*
 * Copyright (C) 2001 Havoc Pennington
 * Copyright (C) 2002 Red Hat, Inc.
 * Copyright (C) 2003 Rob Adams
 * Copyright (C) 2004-2006 Elijah Newren
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#ifndef META_DISPLAY_PRIVATE_H
#define META_DISPLAY_PRIVATE_H

#ifndef PACKAGE
	#error "config.h not included"
#endif

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

#ifdef HAVE_STARTUP_NOTIFICATION
	#include <libsn/sn.h>
#endif

#ifdef HAVE_XSYNC
	#include <X11/extensions/sync.h>
#endif

typedef struct _MetaKeyBinding MetaKeyBinding;
typedef struct _MetaStack      MetaStack;
typedef struct _MetaUISlave    MetaUISlave;
typedef struct _MetaWorkspace  MetaWorkspace;

typedef struct _MetaGroupPropHooks  MetaGroupPropHooks;

typedef struct MetaEdgeResistanceData MetaEdgeResistanceData;

typedef void (*MetaWindowPingFunc) (MetaDisplay* display, Window xwindow, guint32 timestamp, 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

typedef enum {
  META_TILE_NONE,
  META_TILE_LEFT,
  META_TILE_RIGHT,
  META_TILE_MAXIMIZED, /* only used for previews */
  META_TILE_TOP_LEFT,
  META_TILE_TOP_RIGHT,
  META_TILE_BOTTOM_LEFT,
  META_TILE_BOTTOM_RIGHT
} MetaTileMode;

struct _MetaDisplay {
	char* name;
	Display* xdisplay;
	gboolean have_xres; /* Got XRES >= 1.2 */

	Window leader_window;
	Window timestamp_pinging_window;

	/* Pull in all the names of atoms as fields; we will intern them when the
	 * class is constructed.
	 */
	#define item(x)  Atom atom_##x;
		#include "atomnames.h"
	#undef item

	/* This is the actual window from focus events,
	 * not the one we last set
	 */
	MetaWindow* focus_window;

	/* window we are expecting a FocusIn event for or the current focus
	 * window if we are not expecting any FocusIn/FocusOut events; not
	 * perfect because applications can call XSetInputFocus directly.
	 * (It could also be messed up if a timestamp later than current
	 * time is sent to meta_display_set_input_focus_window, though that
	 * would be a programming error).  See bug 154598 for more info.
	 */
	MetaWindow* expected_focus_window;

	/* last timestamp passed to XSetInputFocus */
	guint32 last_focus_time;

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

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

	/* 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.
	 */
	guint allow_terminal_deactivation: 1;

	guint static_gravity_works: 1;

        guint tab_popup_mouse_pressed : 1;

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

	/* 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;
	MetaWindow* autoraise_window;

	/* Alt+click button grabs */
	unsigned int window_grab_modifiers;

	/* current window operation */
	MetaGrabOp  grab_op;
	MetaScreen* grab_screen;
	MetaWindow* grab_window;
	Window      grab_xwindow;
	int         grab_button;
	int         grab_anchor_root_x;
	int         grab_anchor_root_y;
	MetaRectangle grab_anchor_window_pos;
	MetaTileMode  grab_tile_mode;
	int           grab_tile_monitor_number;
	int         grab_latest_motion_x;
	int         grab_latest_motion_y;
	gulong      grab_mask;
	guint       grab_have_pointer : 1;
	guint       grab_have_keyboard : 1;
	guint       grab_wireframe_active : 1;
	guint       grab_was_cancelled : 1;    /* Only used in wireframe mode */
	guint       grab_frame_action : 1;
	MetaRectangle grab_wireframe_rect;
	MetaRectangle grab_wireframe_last_xor_rect;
	MetaRectangle grab_initial_window_pos;
	int         grab_initial_x, grab_initial_y;  /* These are only relevant for */
	gboolean    grab_threshold_movement_reached; /* raise_on_click == FALSE.    */
	MetaResizePopup* grab_resize_popup;
	gint64      grab_last_moveresize_time;
	guint32     grab_motion_notify_time;
	int         grab_wireframe_last_display_width;
	int         grab_wireframe_last_display_height;
	GList*      grab_old_window_stacking;
	MetaEdgeResistanceData* grab_edge_resistance_data;
	unsigned int grab_last_user_action_was_snap;

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

	#ifdef HAVE_XKB
		int         xkb_base_event_type;
		guint32     last_bell_time;
	#endif

	#ifdef HAVE_XSYNC
		/* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
		XSyncAlarm  grab_sync_request_alarm;
	#endif

	int       grab_resize_timeout_id;

	/* Keybindings stuff */
	MetaKeyBinding* key_bindings;
	int             n_key_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;

	/* Opening the display */
	unsigned int display_opening: 1;

	/* Closing down the display */
	int closing;

	/* To detect double clicks
	 *
	 * https://github.com/stefano-k/Mate-Desktop-Environment/commit/b0e5fb03eb21dae8f02692f11ef391bfc5ccba33
	 */
	guint button_click_number;
	Window button_click_window;
	int button_click_x;
	int button_click_y;
	guint32 button_click_time;

	/* Managed by group.c */
	GHashTable* groups_by_leader;

	/* currently-active window menu if any */
	MetaWindowMenu* window_menu;
	MetaWindow* window_with_menu;

	/* Managed by window-props.c */
	gpointer* prop_hooks_table;
	GHashTable* prop_hooks;

	/* Managed by group-props.c */
	MetaGroupPropHooks* group_prop_hooks;

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

	#ifdef HAVE_STARTUP_NOTIFICATION
		SnDisplay* sn_display;
	#endif

	#ifdef HAVE_XSYNC
		int xsync_event_base;
		int xsync_error_base;
	#endif

	#ifdef HAVE_SHAPE
		int shape_event_base;
		int shape_error_base;
	#endif

	#ifdef HAVE_RENDER
		int render_event_base;
		int render_error_base;
	#endif

	#ifdef HAVE_COMPOSITE_EXTENSIONS
		int composite_event_base;
		int composite_error_base;
		int damage_event_base;
		int damage_error_base;
		int xfixes_event_base;
		int xfixes_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)
	#else
		#define META_DISPLAY_HAS_SHAPE(display) FALSE
	#endif

	#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

	#ifdef HAVE_COMPOSITE_EXTENSIONS
		unsigned int have_composite : 1;
		unsigned int have_damage : 1;
		unsigned int have_xfixes : 1;
		#define META_DISPLAY_HAS_COMPOSITE(display) ((display)->have_composite)
		#define META_DISPLAY_HAS_DAMAGE(display) ((display)->have_damage)
		#define META_DISPLAY_HAS_XFIXES(display) ((display)->have_xfixes)
	#else
		#define META_DISPLAY_HAS_COMPOSITE(display) FALSE
		#define META_DISPLAY_HAS_DAMAGE(display) FALSE
		#define META_DISPLAY_HAS_XFIXES(display) FALSE
	#endif
};

/* Xserver time can wraparound, thus comparing two timestamps needs to take
 * this into account.  Here's a little macro to help out.  If no wraparound
 * has occurred, this is equivalent to
 *   time1 < time2
 * Of course, the rest of the ugliness of this macro comes from accounting
 * for the fact that wraparound can occur and the fact that a timestamp of
 * 0 must be special-cased since it means older than anything else.
 *
 * Note that this is NOT an equivalent for time1 <= time2; if that's what
 * you need then you'll need to swap the order of the arguments and negate
 * the result.
 */
#define XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) \
	( (( (time1) < (time2) ) && ( (time2) - (time1) < ((guint32)-1)/2 )) || \
		(( (time1) > (time2) ) && ( (time1) - (time2) > ((guint32)-1)/2 )) \
	)
#define XSERVER_TIME_IS_BEFORE(time1, time2) \
	( (time1) == 0 || \
		(XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) && \
		(time2) != 0) \
	)

gboolean      meta_display_open                (void);
void          meta_display_close               (MetaDisplay *display,
                                                guint32      timestamp);
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);

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

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

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

/* 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);
/* Return whether the xwindow is a no focus window for any of the screens */
gboolean    meta_display_xwindow_is_a_no_focus_window (MetaDisplay *display,
                                                       Window xwindow);

GSList*     meta_display_list_windows        (MetaDisplay *display);

MetaDisplay* meta_display_for_x_display  (Display     *xdisplay);
MetaDisplay* meta_get_display            (void);

Cursor         meta_display_create_x_cursor (MetaDisplay *display,
                                             MetaCursor   cursor);

void     meta_display_set_grab_op_cursor (MetaDisplay *display,
                                          MetaScreen  *screen,
                                          MetaGrabOp   op,
                                          gboolean     change_pointer,
                                          Window       grab_xwindow,
                                          guint32      timestamp);

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

void    meta_display_check_threshold_reached (MetaDisplay *display,
                                              int          x,
                                              int          y);
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,
                                              MetaWindow  *window);
void meta_display_ungrab_focus_window_button (MetaDisplay *display,
                                              MetaWindow  *window);

/* Next two functions are defined in edge-resistance.c */
void meta_display_cleanup_edges              (MetaDisplay *display);

/* 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);

guint32  meta_display_get_current_time           (MetaDisplay *display);
guint32  meta_display_get_current_time_roundtrip (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_set_cursor_theme (const char *theme,
				    int         size);

void meta_display_ping_window      (MetaDisplay        *display,
                                    MetaWindow         *window,
                                    guint32             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,
  META_TAB_LIST_GROUP,
  META_TAB_LIST_NORMAL_ALL_WORKSPACES
} MetaTabList;

typedef enum
{
  META_TAB_SHOW_ICON,      /* Alt-Tab mode */
  META_TAB_SHOW_INSTANTLY  /* Alt-Esc mode */
} MetaTabShowType;

GList* 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);

MetaWindow* meta_display_get_tab_current (MetaDisplay   *display,
                                          MetaTabList    type,
                                          MetaScreen    *screen,
                                          MetaWorkspace *workspace);

int meta_resize_gravity_from_grab_op (MetaGrabOp op);

gboolean meta_grab_op_is_moving   (MetaGrabOp op);
gboolean meta_grab_op_is_resizing (MetaGrabOp op);

void meta_display_devirtualize_modifiers (MetaDisplay        *display,
                                          MetaVirtualModifier modifiers,
                                          unsigned int       *mask);

void meta_display_increment_focus_sentinel (MetaDisplay *display);
void meta_display_decrement_focus_sentinel (MetaDisplay *display);
gboolean meta_display_focus_sentinel_clear (MetaDisplay *display);

/* meta_display_set_input_focus_window is like XSetInputFocus, except
 * that (a) it can't detect timestamps later than the current time,
 * since Marco isn't part of the XServer, and thus gives erroneous
 * behavior in this circumstance (so don't do it), (b) it uses
 * display->last_focus_time since we don't have access to the true
 * Xserver one, (c) it makes use of display->user_time since checking
 * whether a window should be allowed to be focused should depend
 * on user_time events (see bug 167358, comment 15 in particular)
 */
void meta_display_set_input_focus_window   (MetaDisplay *display,
                                            MetaWindow  *window,
                                            gboolean     focus_frame,
                                            guint32      timestamp);

/* meta_display_focus_the_no_focus_window is called when the
 * designated no_focus_window should be focused, but is otherwise the
 * same as meta_display_set_input_focus_window
 */
void meta_display_focus_the_no_focus_window (MetaDisplay *display,
                                             MetaScreen  *screen,
                                             guint32      timestamp);

void meta_display_queue_autoraise_callback  (MetaDisplay *display,
                                             MetaWindow  *window);
void meta_display_remove_autoraise_callback (MetaDisplay *display);

#endif /* META_DISPLAY_PRIVATE_H */