1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
3 /* Mutter interface used by GTK+ UI to talk to core */
4
5 /*
6 * Copyright (C) 2001 Havoc Pennington
7 * Copyright (C) 2003 Rob Adams
8 * Copyright (C) 2004-2006 Elijah Newren
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "config.h"
25
26 #include "x11/meta-x11-window-control.h"
27
28 #include "core/frame.h"
29 #include "core/meta-workspace-manager-private.h"
30 #include "core/util-private.h"
31 #include "core/workspace-private.h"
32 #include "meta/meta-x11-errors.h"
33 #include "meta/prefs.h"
34 #include "x11/meta-x11-display-private.h"
35 #include "x11/window-x11-private.h"
36 #include "x11/window-x11.h"
37
38 static MetaWindow *
window_from_frame(MetaX11Display * x11_display,Window frame_xwindow)39 window_from_frame (MetaX11Display *x11_display,
40 Window frame_xwindow)
41 {
42 MetaWindow *window;
43
44 window = meta_x11_display_lookup_x_window (x11_display, frame_xwindow);
45 if (!window || !window->frame)
46 {
47 meta_bug ("No such frame window 0x%lx!", frame_xwindow);
48 return NULL;
49 }
50
51 return window;
52 }
53
54 void
meta_x11_wm_queue_frame_resize(MetaX11Display * x11_display,Window frame_xwindow)55 meta_x11_wm_queue_frame_resize (MetaX11Display *x11_display,
56 Window frame_xwindow)
57 {
58 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
59
60 meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
61 meta_window_frame_size_changed (window);
62 }
63
64 void
meta_x11_wm_user_lower_and_unfocus(MetaX11Display * x11_display,Window frame_xwindow,uint32_t timestamp)65 meta_x11_wm_user_lower_and_unfocus (MetaX11Display *x11_display,
66 Window frame_xwindow,
67 uint32_t timestamp)
68 {
69 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
70
71 meta_window_lower_with_transients (window, timestamp);
72 }
73
74 void
meta_x11_wm_toggle_maximize_vertically(MetaX11Display * x11_display,Window frame_xwindow)75 meta_x11_wm_toggle_maximize_vertically (MetaX11Display *x11_display,
76 Window frame_xwindow)
77 {
78 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
79
80 if (meta_prefs_get_raise_on_click ())
81 meta_window_raise (window);
82
83 if (META_WINDOW_MAXIMIZED_VERTICALLY (window))
84 meta_window_unmaximize (window, META_MAXIMIZE_VERTICAL);
85 else
86 meta_window_maximize (window, META_MAXIMIZE_VERTICAL);
87 }
88
89 void
meta_x11_wm_toggle_maximize_horizontally(MetaX11Display * x11_display,Window frame_xwindow)90 meta_x11_wm_toggle_maximize_horizontally (MetaX11Display *x11_display,
91 Window frame_xwindow)
92 {
93 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
94
95 if (meta_prefs_get_raise_on_click ())
96 meta_window_raise (window);
97
98 if (META_WINDOW_MAXIMIZED_HORIZONTALLY (window))
99 meta_window_unmaximize (window, META_MAXIMIZE_HORIZONTAL);
100 else
101 meta_window_maximize (window, META_MAXIMIZE_HORIZONTAL);
102 }
103
104 void
meta_x11_wm_toggle_maximize(MetaX11Display * x11_display,Window frame_xwindow)105 meta_x11_wm_toggle_maximize (MetaX11Display *x11_display,
106 Window frame_xwindow)
107 {
108 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
109
110 if (meta_prefs_get_raise_on_click ())
111 meta_window_raise (window);
112
113 if (META_WINDOW_MAXIMIZED (window))
114 meta_window_unmaximize (window, META_MAXIMIZE_BOTH);
115 else
116 meta_window_maximize (window, META_MAXIMIZE_BOTH);
117 }
118
119 void
meta_x11_wm_show_window_menu(MetaX11Display * x11_display,Window frame_xwindow,MetaWindowMenuType menu,int root_x,int root_y,uint32_t timestamp)120 meta_x11_wm_show_window_menu (MetaX11Display *x11_display,
121 Window frame_xwindow,
122 MetaWindowMenuType menu,
123 int root_x,
124 int root_y,
125 uint32_t timestamp)
126 {
127 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
128
129 if (meta_prefs_get_raise_on_click ())
130 meta_window_raise (window);
131 meta_window_focus (window, timestamp);
132
133 meta_window_show_menu (window, menu, root_x, root_y);
134 }
135
136 void
meta_x11_wm_show_window_menu_for_rect(MetaX11Display * x11_display,Window frame_xwindow,MetaWindowMenuType menu,MetaRectangle * rect,uint32_t timestamp)137 meta_x11_wm_show_window_menu_for_rect (MetaX11Display *x11_display,
138 Window frame_xwindow,
139 MetaWindowMenuType menu,
140 MetaRectangle *rect,
141 uint32_t timestamp)
142 {
143 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
144
145 if (meta_prefs_get_raise_on_click ())
146 meta_window_raise (window);
147 meta_window_focus (window, timestamp);
148
149 meta_window_show_menu_for_rect (window, menu, rect);
150 }
151
152 gboolean
meta_x11_wm_begin_grab_op(MetaX11Display * x11_display,Window frame_xwindow,MetaGrabOp op,gboolean pointer_already_grabbed,gboolean frame_action,int button,gulong modmask,uint32_t timestamp,int root_x,int root_y)153 meta_x11_wm_begin_grab_op (MetaX11Display *x11_display,
154 Window frame_xwindow,
155 MetaGrabOp op,
156 gboolean pointer_already_grabbed,
157 gboolean frame_action,
158 int button,
159 gulong modmask,
160 uint32_t timestamp,
161 int root_x,
162 int root_y)
163 {
164 MetaWindow *window = window_from_frame (x11_display, frame_xwindow);
165 MetaDisplay *display;
166
167 display = meta_x11_display_get_display (x11_display);
168
169 return meta_display_begin_grab_op (display, window,
170 op, pointer_already_grabbed,
171 frame_action,
172 button, modmask,
173 timestamp, root_x, root_y);
174 }
175
176 void
meta_x11_wm_end_grab_op(MetaX11Display * x11_display,uint32_t timestamp)177 meta_x11_wm_end_grab_op (MetaX11Display *x11_display,
178 uint32_t timestamp)
179 {
180 MetaDisplay *display;
181
182 display = meta_x11_display_get_display (x11_display);
183
184 meta_display_end_grab_op (display, timestamp);
185 }
186
187 MetaGrabOp
meta_x11_wm_get_grab_op(MetaX11Display * x11_display)188 meta_x11_wm_get_grab_op (MetaX11Display *x11_display)
189 {
190 MetaDisplay *display;
191
192 display = meta_x11_display_get_display (x11_display);
193
194 return display->grab_op;
195 }
196
197 void
meta_x11_wm_grab_buttons(MetaX11Display * x11_display,Window frame_xwindow)198 meta_x11_wm_grab_buttons (MetaX11Display *x11_display,
199 Window frame_xwindow)
200 {
201 MetaDisplay *display;
202
203 display = meta_x11_display_get_display (x11_display);
204
205 meta_verbose ("Grabbing buttons on frame 0x%lx", frame_xwindow);
206 meta_display_grab_window_buttons (display, frame_xwindow);
207 }
208
209 void
meta_x11_wm_set_screen_cursor(MetaX11Display * x11_display,Window frame_on_screen,MetaCursor cursor)210 meta_x11_wm_set_screen_cursor (MetaX11Display *x11_display,
211 Window frame_on_screen,
212 MetaCursor cursor)
213 {
214 MetaWindow *window = window_from_frame (x11_display, frame_on_screen);
215
216 meta_frame_set_screen_cursor (window->frame, cursor);
217 }
218