| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 |
* Copyright (C) 1998-2004 Tor Lillqvist |
| 4 |
* Copyright (C) 2001-2011 Hans Breuer |
| 5 |
* Copyright (C) 2007-2009 Cody Russell |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
| 23 |
* file for a list of people on the GTK+ Team. See the ChangeLog |
| 24 |
* files for a list of changes. These files are distributed with |
| 25 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
#include <stdlib.h> |
| 30 |
|
| 31 |
#include "gdk.h" |
| 32 |
#include "gdkwindowimpl.h" |
| 33 |
#include "gdkprivate-win32.h" |
| 34 |
#include "gdkdeviceprivate.h" |
| 35 |
#include "gdkdevicemanager-win32.h" |
| 36 |
#include "gdkenumtypes.h" |
| 37 |
#include "gdkwin32.h" |
| 38 |
#include "gdkdisplayprivate.h" |
| 39 |
#include "gdkvisualprivate.h" |
| 40 |
#include "gdkmonitorprivate.h" |
| 41 |
#include "gdkwin32window.h" |
| 42 |
#include "gdkglcontext-win32.h" |
| 43 |
#include "gdkdisplay-win32.h" |
| 44 |
|
| 45 |
#include <cairo-win32.h> |
| 46 |
#include <dwmapi.h> |
| 47 |
#include <math.h> |
| 48 |
#include "fallback-c89.c" |
| 49 |
|
| 50 |
static void gdk_window_impl_win32_init (GdkWindowImplWin32 *window); |
| 51 |
static void gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass); |
| 52 |
static void gdk_window_impl_win32_finalize (GObject *object); |
| 53 |
|
| 54 |
static gpointer parent_class = NULL; |
| 55 |
static GSList *modal_window_stack = NULL; |
| 56 |
|
| 57 |
static const cairo_user_data_key_t gdk_win32_cairo_key; |
| 58 |
typedef struct _FullscreenInfo FullscreenInfo; |
| 59 |
|
| 60 |
struct _FullscreenInfo |
| 61 |
{ |
| 62 |
RECT r; |
| 63 |
guint hint_flags; |
| 64 |
LONG style; |
| 65 |
}; |
| 66 |
|
| 67 |
struct _AeroSnapEdgeRegion |
| 68 |
{ |
| 69 |
/* The rectangle along the edge of the desktop |
| 70 |
* that allows application of the snap transformation. |
| 71 |
*/ |
| 72 |
GdkRectangle edge; |
| 73 |
|
| 74 |
/* A subregion of the "edge". When the pointer hits |
| 75 |
* this region, the transformation is revealed. |
| 76 |
* Usually it is 1-pixel thick and is located at the |
| 77 |
* very edge of the screen. When there's a toolbar |
| 78 |
* at that edge, the "trigger" and the "edge" regions |
| 79 |
* are extended to cover that toolbar. |
| 80 |
*/ |
| 81 |
GdkRectangle trigger; |
| 82 |
}; |
| 83 |
|
| 84 |
typedef struct _AeroSnapEdgeRegion AeroSnapEdgeRegion; |
| 85 |
|
| 86 |
/* Use this for hWndInsertAfter (2nd argument to SetWindowPos()) if |
| 87 |
* SWP_NOZORDER flag is used. Otherwise it's unobvious why a particular |
| 88 |
* argument is used. Using NULL is misleading, because |
| 89 |
* NULL is equivalent to HWND_TOP. |
| 90 |
*/ |
| 91 |
#define SWP_NOZORDER_SPECIFIED HWND_TOP |
| 92 |
|
| 93 |
/* Size of the regions at the edges of the desktop where |
| 94 |
* snapping can take place (in pixels) |
| 95 |
*/ |
| 96 |
#define AEROSNAP_REGION_THICKNESS (20) |
| 97 |
/* Size of the subregions that actually trigger the snapping prompt |
| 98 |
* (in pixels). |
| 99 |
*/ |
| 100 |
#define AEROSNAP_REGION_TRIGGER_THICKNESS (1) |
| 101 |
|
| 102 |
/* The gap between the snap indicator and the edge of the work area |
| 103 |
* (in pixels). |
| 104 |
*/ |
| 105 |
#define AEROSNAP_INDICATOR_EDGE_GAP (10) |
| 106 |
|
| 107 |
/* Width of the outline of the snap indicator |
| 108 |
* (in pixels). |
| 109 |
*/ |
| 110 |
#define AEROSNAP_INDICATOR_LINE_WIDTH (3.0) |
| 111 |
|
| 112 |
/* Corner radius of the snap indicator. |
| 113 |
*/ |
| 114 |
#define AEROSNAP_INDICATOR_CORNER_RADIUS (3.0) |
| 115 |
|
| 116 |
/* The time it takes for snap indicator to expand/shrink |
| 117 |
* from current window size to future position of the |
| 118 |
* snapped window (in microseconds). |
| 119 |
*/ |
| 120 |
#define AEROSNAP_INDICATOR_ANIMATION_DURATION (200 * 1000) |
| 121 |
|
| 122 |
/* Opacity if the snap indicator. */ |
| 123 |
#define AEROSNAP_INDICATOR_OPACITY (0.5) |
| 124 |
|
| 125 |
/* The interval between snap indicator redraws (in milliseconds). |
| 126 |
* 16 is ~ 1/60 of a second, for ~60 FPS. |
| 127 |
*/ |
| 128 |
#define AEROSNAP_INDICATOR_ANIMATION_TICK (16) |
| 129 |
|
| 130 |
static gboolean _gdk_window_get_functions (GdkWindow *window, |
| 131 |
GdkWMFunction *functions); |
| 132 |
static HDC _gdk_win32_impl_acquire_dc (GdkWindowImplWin32 *impl); |
| 133 |
static void _gdk_win32_impl_release_dc (GdkWindowImplWin32 *impl); |
| 134 |
|
| 135 |
#define WINDOW_IS_TOPLEVEL(window) \ |
| 136 |
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ |
| 137 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN && \ |
| 138 |
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) |
| 139 |
|
| 140 |
GdkScreen * |
| 141 |
GDK_WINDOW_SCREEN (GObject *win) |
| 142 |
{ |
| 143 |
return gdk_display_get_default_screen (gdk_display_get_default ()); |
| 144 |
} |
| 145 |
|
| 146 |
struct _GdkWin32Window { |
| 147 |
GdkWindow parent; |
| 148 |
}; |
| 149 |
|
| 150 |
struct _GdkWin32WindowClass { |
| 151 |
GdkWindowClass parent_class; |
| 152 |
}; |
| 153 |
|
| 154 |
G_DEFINE_TYPE (GdkWin32Window, gdk_win32_window, GDK_TYPE_WINDOW) |
| 155 |
|
| 156 |
static void |
| 157 |
gdk_win32_window_class_init (GdkWin32WindowClass *window_class) |
| 158 |
{ |
| 159 |
} |
| 160 |
|
| 161 |
static void |
| 162 |
gdk_win32_window_init (GdkWin32Window *window) |
| 163 |
{ |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
G_DEFINE_TYPE (GdkWindowImplWin32, gdk_window_impl_win32, GDK_TYPE_WINDOW_IMPL) |
| 168 |
|
| 169 |
GType |
| 170 |
_gdk_window_impl_win32_get_type (void) |
| 171 |
{ |
| 172 |
static GType object_type = 0; |
| 173 |
|
| 174 |
if (!object_type) |
| 175 |
{ |
| 176 |
const GTypeInfo object_info = |
| 177 |
{ |
| 178 |
sizeof (GdkWindowImplWin32Class), |
| 179 |
(GBaseInitFunc) NULL, |
| 180 |
(GBaseFinalizeFunc) NULL, |
| 181 |
(GClassInitFunc) gdk_window_impl_win32_class_init, |
| 182 |
NULL, /* class_finalize */ |
| 183 |
NULL, /* class_data */ |
| 184 |
sizeof (GdkWindowImplWin32), |
| 185 |
0, /* n_preallocs */ |
| 186 |
(GInstanceInitFunc) gdk_window_impl_win32_init, |
| 187 |
}; |
| 188 |
|
| 189 |
object_type = g_type_register_static (GDK_TYPE_WINDOW_IMPL, |
| 190 |
"GdkWindowImplWin32", |
| 191 |
&object_info, 0); |
| 192 |
} |
| 193 |
|
| 194 |
return object_type; |
| 195 |
} |
| 196 |
|
| 197 |
static void |
| 198 |
gdk_window_impl_win32_init (GdkWindowImplWin32 *impl) |
| 199 |
{ |
| 200 |
GdkDisplay *display = gdk_display_get_default (); |
| 201 |
|
| 202 |
impl->toplevel_window_type = -1; |
| 203 |
impl->cursor = NULL; |
| 204 |
impl->hicon_big = NULL; |
| 205 |
impl->hicon_small = NULL; |
| 206 |
impl->hint_flags = 0; |
| 207 |
impl->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL; |
| 208 |
impl->transient_owner = NULL; |
| 209 |
impl->transient_children = NULL; |
| 210 |
impl->num_transients = 0; |
| 211 |
impl->changing_state = FALSE; |
| 212 |
impl->window_scale = 1; |
| 213 |
|
| 214 |
if (display != NULL) |
| 215 |
/* Replace WM-defined default cursor with the default cursor |
| 216 |
* from our theme. Otherwise newly-opened windows (such as popup |
| 217 |
* menus of all kinds) will have WM-default cursor when they are |
| 218 |
* first shown, which will be replaced by our cursor only later on. |
| 219 |
*/ |
| 220 |
impl->cursor = _gdk_win32_display_get_cursor_for_type (display, GDK_LEFT_PTR); |
| 221 |
} |
| 222 |
|
| 223 |
static void |
| 224 |
gdk_window_impl_win32_finalize (GObject *object) |
| 225 |
{ |
| 226 |
GdkWindow *wrapper; |
| 227 |
GdkWindowImplWin32 *window_impl; |
| 228 |
|
| 229 |
g_return_if_fail (GDK_IS_WINDOW_IMPL_WIN32 (object)); |
| 230 |
|
| 231 |
window_impl = GDK_WINDOW_IMPL_WIN32 (object); |
| 232 |
|
| 233 |
wrapper = window_impl->wrapper; |
| 234 |
|
| 235 |
if (!GDK_WINDOW_DESTROYED (wrapper)) |
| 236 |
{ |
| 237 |
gdk_win32_handle_table_remove (window_impl->handle); |
| 238 |
} |
| 239 |
|
| 240 |
g_clear_object (&window_impl->cursor); |
| 241 |
|
| 242 |
g_clear_pointer (&window_impl->snap_stash, g_free); |
| 243 |
g_clear_pointer (&window_impl->snap_stash_int, g_free); |
| 244 |
|
| 245 |
if (window_impl->hicon_big != NULL) |
| 246 |
{ |
| 247 |
GDI_CALL (DestroyIcon, (window_impl->hicon_big)); |
| 248 |
window_impl->hicon_big = NULL; |
| 249 |
} |
| 250 |
|
| 251 |
if (window_impl->hicon_small != NULL) |
| 252 |
{ |
| 253 |
GDI_CALL (DestroyIcon, (window_impl->hicon_small)); |
| 254 |
window_impl->hicon_small = NULL; |
| 255 |
} |
| 256 |
|
| 257 |
g_free (window_impl->decorations); |
| 258 |
|
| 259 |
if (window_impl->cache_surface) |
| 260 |
{ |
| 261 |
cairo_surface_destroy (window_impl->cache_surface); |
| 262 |
window_impl->cache_surface = NULL; |
| 263 |
} |
| 264 |
|
| 265 |
if (window_impl->cairo_surface) |
| 266 |
{ |
| 267 |
cairo_surface_destroy (window_impl->cairo_surface); |
| 268 |
window_impl->cairo_surface = NULL; |
| 269 |
} |
| 270 |
|
| 271 |
g_assert (window_impl->transient_owner == NULL); |
| 272 |
g_assert (window_impl->transient_children == NULL); |
| 273 |
|
| 274 |
G_OBJECT_CLASS (parent_class)->finalize (object); |
| 275 |
} |
| 276 |
|
| 277 |
static void |
| 278 |
gdk_win32_get_window_client_area_rect (GdkWindow *window, |
| 279 |
gint scale, |
| 280 |
RECT *rect) |
| 281 |
{ |
| 282 |
gint x, y, width, height; |
| 283 |
|
| 284 |
gdk_window_get_position (window, &x, &y); |
| 285 |
width = gdk_window_get_width (window); |
| 286 |
height = gdk_window_get_height (window); |
| 287 |
rect->left = x * scale; |
| 288 |
rect->top = y * scale; |
| 289 |
rect->right = rect->left + width * scale; |
| 290 |
rect->bottom = rect->top + height * scale; |
| 291 |
} |
| 292 |
|
| 293 |
static void |
| 294 |
gdk_win32_window_get_queued_window_rect (GdkWindow *window, |
| 295 |
RECT *return_window_rect) |
| 296 |
{ |
| 297 |
RECT window_rect; |
| 298 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 299 |
|
| 300 |
gdk_win32_get_window_client_area_rect (window, impl->window_scale, &window_rect); |
| 301 |
|
| 302 |
/* Turn client area into window area */ |
| 303 |
_gdk_win32_adjust_client_rect (window, &window_rect); |
| 304 |
|
| 305 |
/* Convert GDK screen coordinates to W32 desktop coordinates */ |
| 306 |
window_rect.left -= _gdk_offset_x; |
| 307 |
window_rect.right -= _gdk_offset_x; |
| 308 |
window_rect.top -= _gdk_offset_y; |
| 309 |
window_rect.bottom -= _gdk_offset_y; |
| 310 |
|
| 311 |
*return_window_rect = window_rect; |
| 312 |
} |
| 313 |
|
| 314 |
static void |
| 315 |
gdk_win32_window_apply_queued_move_resize (GdkWindow *window, |
| 316 |
RECT window_rect) |
| 317 |
{ |
| 318 |
if (!IsIconic (GDK_WINDOW_HWND (window))) |
| 319 |
{ |
| 320 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 321 |
GDK_NOTE (EVENTS, g_print ("Setting window position ... ")); |
| 322 |
|
| 323 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 324 |
SWP_NOZORDER_SPECIFIED, |
| 325 |
window_rect.left, window_rect.top, |
| 326 |
window_rect.right - window_rect.left, |
| 327 |
window_rect.bottom - window_rect.top, |
| 328 |
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW)); |
| 329 |
|
| 330 |
GDK_NOTE (EVENTS, g_print (" ... set window position\n")); |
| 331 |
|
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
/* Don't move iconic windows */ |
| 336 |
/* TODO: use SetWindowPlacement() to change non-minimized window position */ |
| 337 |
} |
| 338 |
|
| 339 |
static gboolean |
| 340 |
gdk_win32_window_begin_paint (GdkWindow *window) |
| 341 |
{ |
| 342 |
GdkWindowImplWin32 *impl; |
| 343 |
RECT window_rect; |
| 344 |
|
| 345 |
if (window == NULL || GDK_WINDOW_DESTROYED (window)) |
| 346 |
return TRUE; |
| 347 |
|
| 348 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 349 |
|
| 350 |
/* Layered windows are moved *after* repaint. |
| 351 |
* We supply our own surface, return FALSE to make GDK use it. |
| 352 |
*/ |
| 353 |
if (impl->layered) |
| 354 |
return FALSE; |
| 355 |
|
| 356 |
/* Non-GL windows are moved *after* repaint. |
| 357 |
* We don't supply our own surface, return TRUE to make GDK create |
| 358 |
* one by itself. |
| 359 |
*/ |
| 360 |
if (!window->current_paint.use_gl) |
| 361 |
return TRUE; |
| 362 |
|
| 363 |
/* GL windows are moved *before* repaint (otherwise |
| 364 |
* repainting doesn't work), but if there's no move queued up, |
| 365 |
* return immediately. Doesn't matter what we return, GDK |
| 366 |
* will create a surface anyway, as if we returned TRUE. |
| 367 |
*/ |
| 368 |
if (!impl->drag_move_resize_context.native_move_resize_pending) |
| 369 |
return TRUE; |
| 370 |
|
| 371 |
impl->drag_move_resize_context.native_move_resize_pending = FALSE; |
| 372 |
|
| 373 |
/* Get the position/size of the window that GDK wants, |
| 374 |
* apply it. |
| 375 |
*/ |
| 376 |
gdk_win32_window_get_queued_window_rect (window, &window_rect); |
| 377 |
gdk_win32_window_apply_queued_move_resize (window, window_rect); |
| 378 |
|
| 379 |
return TRUE; |
| 380 |
} |
| 381 |
|
| 382 |
static void |
| 383 |
gdk_win32_window_end_paint (GdkWindow *window) |
| 384 |
{ |
| 385 |
GdkWindowImplWin32 *impl; |
| 386 |
RECT window_rect; |
| 387 |
HDC hdc; |
| 388 |
POINT window_position; |
| 389 |
SIZE window_size; |
| 390 |
POINT source_point; |
| 391 |
BLENDFUNCTION blender; |
| 392 |
cairo_t *cr; |
| 393 |
|
| 394 |
if (window == NULL || GDK_WINDOW_DESTROYED (window)) |
| 395 |
return; |
| 396 |
|
| 397 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 398 |
|
| 399 |
/* GL windows are moved *before* repaint */ |
| 400 |
if (window->current_paint.use_gl) |
| 401 |
return; |
| 402 |
|
| 403 |
/* No move/resize is queued up, and we don't need to update |
| 404 |
* the contents of a layered window, so return immediately. |
| 405 |
*/ |
| 406 |
if (!impl->layered && |
| 407 |
!impl->drag_move_resize_context.native_move_resize_pending) |
| 408 |
return; |
| 409 |
|
| 410 |
impl->drag_move_resize_context.native_move_resize_pending = FALSE; |
| 411 |
|
| 412 |
/* Get the position/size of the window that GDK wants. */ |
| 413 |
gdk_win32_window_get_queued_window_rect (window, &window_rect); |
| 414 |
|
| 415 |
if (!impl->layered) |
| 416 |
{ |
| 417 |
gdk_win32_window_apply_queued_move_resize (window, window_rect); |
| 418 |
|
| 419 |
return; |
| 420 |
} |
| 421 |
|
| 422 |
window_position.x = window_rect.left; |
| 423 |
window_position.y = window_rect.top; |
| 424 |
|
| 425 |
window_size.cx = window_rect.right - window_rect.left; |
| 426 |
window_size.cy = window_rect.bottom - window_rect.top; |
| 427 |
|
| 428 |
cairo_surface_flush (impl->cairo_surface); |
| 429 |
|
| 430 |
/* we always draw in the top-left corner of the surface */ |
| 431 |
source_point.x = source_point.y = 0; |
| 432 |
|
| 433 |
blender.BlendOp = AC_SRC_OVER; |
| 434 |
blender.BlendFlags = 0; |
| 435 |
blender.AlphaFormat = AC_SRC_ALPHA; |
| 436 |
blender.SourceConstantAlpha = impl->layered_opacity * 255; |
| 437 |
|
| 438 |
/* Update cache surface contents */ |
| 439 |
cr = cairo_create (impl->cache_surface); |
| 440 |
|
| 441 |
cairo_set_source_surface (cr, window->current_paint.surface, 0, 0); |
| 442 |
gdk_cairo_region (cr, window->current_paint.region); |
| 443 |
cairo_clip (cr); |
| 444 |
|
| 445 |
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
| 446 |
cairo_paint (cr); |
| 447 |
|
| 448 |
cairo_destroy (cr); |
| 449 |
|
| 450 |
cairo_surface_flush (impl->cache_surface); |
| 451 |
hdc = cairo_win32_surface_get_dc (impl->cache_surface); |
| 452 |
|
| 453 |
/* Don't use UpdateLayeredWindow on minimized windows */ |
| 454 |
if (IsIconic (GDK_WINDOW_HWND (window))) |
| 455 |
{ |
| 456 |
gdk_win32_window_apply_queued_move_resize (window, window_rect); |
| 457 |
|
| 458 |
return; |
| 459 |
} |
| 460 |
|
| 461 |
/* Move, resize and redraw layered window in one call */ |
| 462 |
API_CALL (UpdateLayeredWindow, (GDK_WINDOW_HWND (window), NULL, |
| 463 |
&window_position, &window_size, |
| 464 |
hdc, &source_point, |
| 465 |
0, &blender, ULW_ALPHA)); |
| 466 |
} |
| 467 |
|
| 468 |
void |
| 469 |
_gdk_win32_adjust_client_rect (GdkWindow *window, |
| 470 |
RECT *rect) |
| 471 |
{ |
| 472 |
LONG style, exstyle; |
| 473 |
|
| 474 |
style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE); |
| 475 |
exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE); |
| 476 |
API_CALL (AdjustWindowRectEx, (rect, style, FALSE, exstyle)); |
| 477 |
} |
| 478 |
|
| 479 |
gboolean |
| 480 |
_gdk_win32_window_enable_transparency (GdkWindow *window) |
| 481 |
{ |
| 482 |
GdkWindowImplWin32 *impl; |
| 483 |
GdkScreen *screen; |
| 484 |
DWM_BLURBEHIND blur_behind; |
| 485 |
HRGN empty_region; |
| 486 |
HRESULT call_result; |
| 487 |
HWND parent, thiswindow; |
| 488 |
|
| 489 |
if (window == NULL || GDK_WINDOW_HWND (window) == NULL) |
| 490 |
return FALSE; |
| 491 |
|
| 492 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 493 |
|
| 494 |
/* layered windows don't need blurbehind for transparency */ |
| 495 |
if (impl->layered) |
| 496 |
return TRUE; |
| 497 |
|
| 498 |
screen = gdk_window_get_screen (window); |
| 499 |
|
| 500 |
if (!gdk_screen_is_composited (screen)) |
| 501 |
return FALSE; |
| 502 |
|
| 503 |
if (window == gdk_screen_get_root_window (screen)) |
| 504 |
return FALSE; |
| 505 |
|
| 506 |
thiswindow = GDK_WINDOW_HWND (window); |
| 507 |
|
| 508 |
/* Blurbehind only works on toplevel windows */ |
| 509 |
parent = GetAncestor (thiswindow, GA_PARENT); |
| 510 |
if (!(GetWindowLong (thiswindow, GWL_STYLE) & WS_POPUP) && |
| 511 |
(parent == NULL || parent != GetDesktopWindow ())) |
| 512 |
return FALSE; |
| 513 |
|
| 514 |
empty_region = CreateRectRgn (0, 0, -1, -1); |
| 515 |
|
| 516 |
if (empty_region == NULL) |
| 517 |
return FALSE; |
| 518 |
|
| 519 |
memset (&blur_behind, 0, sizeof (blur_behind)); |
| 520 |
blur_behind.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; |
| 521 |
blur_behind.hRgnBlur = empty_region; |
| 522 |
blur_behind.fEnable = TRUE; |
| 523 |
call_result = DwmEnableBlurBehindWindow (thiswindow, &blur_behind); |
| 524 |
|
| 525 |
if (!SUCCEEDED (call_result)) |
| 526 |
g_warning ("%s: %s (%p) failed: %" G_GINT32_MODIFIER "x", |
| 527 |
G_STRLOC, "DwmEnableBlurBehindWindow", thiswindow, (guint32) call_result); |
| 528 |
|
| 529 |
DeleteObject (empty_region); |
| 530 |
|
| 531 |
return SUCCEEDED (call_result); |
| 532 |
} |
| 533 |
|
| 534 |
static const gchar * |
| 535 |
get_default_title (void) |
| 536 |
{ |
| 537 |
const char *title; |
| 538 |
title = g_get_application_name (); |
| 539 |
if (!title) |
| 540 |
title = g_get_prgname (); |
| 541 |
|
| 542 |
return title; |
| 543 |
} |
| 544 |
|
| 545 |
/* RegisterGdkClass |
| 546 |
* is a wrapper function for RegisterWindowClassEx. |
| 547 |
* It creates at least one unique class for every |
| 548 |
* GdkWindowType. If support for single window-specific icons |
| 549 |
* is ever needed (e.g Dialog specific), every such window should |
| 550 |
* get its own class |
| 551 |
*/ |
| 552 |
static ATOM |
| 553 |
RegisterGdkClass (GdkWindowType wtype, GdkWindowTypeHint wtype_hint) |
| 554 |
{ |
| 555 |
static ATOM klassTOPLEVEL = 0; |
| 556 |
static ATOM klassCHILD = 0; |
| 557 |
static ATOM klassTEMP = 0; |
| 558 |
static HICON hAppIcon = NULL; |
| 559 |
static HICON hAppIconSm = NULL; |
| 560 |
static WNDCLASSEXW wcl; |
| 561 |
ATOM klass = 0; |
| 562 |
|
| 563 |
wcl.cbSize = sizeof (WNDCLASSEX); |
| 564 |
wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw |
| 565 |
* on WM_SIZE and WM_MOVE. Flicker, Performance! |
| 566 |
*/ |
| 567 |
wcl.lpfnWndProc = _gdk_win32_window_procedure; |
| 568 |
wcl.cbClsExtra = 0; |
| 569 |
wcl.cbWndExtra = 0; |
| 570 |
wcl.hInstance = _gdk_app_hmodule; |
| 571 |
wcl.hIcon = 0; |
| 572 |
wcl.hIconSm = 0; |
| 573 |
|
| 574 |
/* initialize once! */ |
| 575 |
if (0 == hAppIcon && 0 == hAppIconSm) |
| 576 |
{ |
| 577 |
gchar sLoc [MAX_PATH+1]; |
| 578 |
|
| 579 |
if (0 != GetModuleFileName (_gdk_app_hmodule, sLoc, MAX_PATH)) |
| 580 |
{ |
| 581 |
ExtractIconEx (sLoc, 0, &hAppIcon, &hAppIconSm, 1); |
| 582 |
|
| 583 |
if (0 == hAppIcon && 0 == hAppIconSm) |
| 584 |
{ |
| 585 |
if (0 != GetModuleFileName (_gdk_dll_hinstance, sLoc, MAX_PATH)) |
| 586 |
{ |
| 587 |
ExtractIconEx (sLoc, 0, &hAppIcon, &hAppIconSm, 1); |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
if (0 == hAppIcon && 0 == hAppIconSm) |
| 593 |
{ |
| 594 |
hAppIcon = LoadImage (NULL, IDI_APPLICATION, IMAGE_ICON, |
| 595 |
GetSystemMetrics (SM_CXICON), |
| 596 |
GetSystemMetrics (SM_CYICON), 0); |
| 597 |
hAppIconSm = LoadImage (NULL, IDI_APPLICATION, IMAGE_ICON, |
| 598 |
GetSystemMetrics (SM_CXSMICON), |
| 599 |
GetSystemMetrics (SM_CYSMICON), 0); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
if (0 == hAppIcon) |
| 604 |
hAppIcon = hAppIconSm; |
| 605 |
else if (0 == hAppIconSm) |
| 606 |
hAppIconSm = hAppIcon; |
| 607 |
|
| 608 |
wcl.lpszMenuName = NULL; |
| 609 |
|
| 610 |
/* initialize once per class */ |
| 611 |
/* |
| 612 |
* HB: Setting the background brush leads to flicker, because we |
| 613 |
* don't get asked how to clear the background. This is not what |
| 614 |
* we want, at least not for input_only windows ... |
| 615 |
*/ |
| 616 |
#define ONCE_PER_CLASS() \ |
| 617 |
wcl.hIcon = CopyIcon (hAppIcon); \ |
| 618 |
wcl.hIconSm = CopyIcon (hAppIconSm); \ |
| 619 |
wcl.hbrBackground = NULL; \ |
| 620 |
wcl.hCursor = LoadCursor (NULL, IDC_ARROW); |
| 621 |
|
| 622 |
switch (wtype) |
| 623 |
{ |
| 624 |
case GDK_WINDOW_TOPLEVEL: |
| 625 |
/* MSDN: CS_OWNDC is needed for OpenGL contexts */ |
| 626 |
wcl.style |= CS_OWNDC; |
| 627 |
if (0 == klassTOPLEVEL) |
| 628 |
{ |
| 629 |
wcl.lpszClassName = L"gdkWindowToplevel"; |
| 630 |
|
| 631 |
ONCE_PER_CLASS (); |
| 632 |
klassTOPLEVEL = RegisterClassExW (&wcl); |
| 633 |
} |
| 634 |
klass = klassTOPLEVEL; |
| 635 |
break; |
| 636 |
|
| 637 |
case GDK_WINDOW_CHILD: |
| 638 |
if (0 == klassCHILD) |
| 639 |
{ |
| 640 |
wcl.lpszClassName = L"gdkWindowChild"; |
| 641 |
|
| 642 |
/* XXX: Find out whether GL Widgets are done for GDK_WINDOW_CHILD |
| 643 |
* MSDN says CS_PARENTDC should not be used for GL Context |
| 644 |
* creation |
| 645 |
*/ |
| 646 |
wcl.style |= CS_PARENTDC; /* MSDN: ... enhances system performance. */ |
| 647 |
ONCE_PER_CLASS (); |
| 648 |
klassCHILD = RegisterClassExW (&wcl); |
| 649 |
} |
| 650 |
klass = klassCHILD; |
| 651 |
break; |
| 652 |
|
| 653 |
case GDK_WINDOW_TEMP: |
| 654 |
if (klassTEMP == 0) |
| 655 |
{ |
| 656 |
wcl.lpszClassName = L"gdkWindowTemp"; |
| 657 |
wcl.style |= CS_SAVEBITS; |
| 658 |
ONCE_PER_CLASS (); |
| 659 |
klassTEMP = RegisterClassExW (&wcl); |
| 660 |
} |
| 661 |
|
| 662 |
klass = klassTEMP; |
| 663 |
|
| 664 |
break; |
| 665 |
|
| 666 |
default: |
| 667 |
g_assert_not_reached (); |
| 668 |
break; |
| 669 |
} |
| 670 |
|
| 671 |
if (klass == 0) |
| 672 |
{ |
| 673 |
WIN32_API_FAILED ("RegisterClassExW"); |
| 674 |
g_error ("That is a fatal error"); |
| 675 |
} |
| 676 |
return klass; |
| 677 |
} |
| 678 |
|
| 679 |
/* |
| 680 |
* Create native windows. |
| 681 |
* |
| 682 |
* With the default Gdk the created windows are mostly toplevel windows. |
| 683 |
* |
| 684 |
* Placement of the window is derived from the passed in window, |
| 685 |
* except for toplevel window where OS/Window Manager placement |
| 686 |
* is used. |
| 687 |
* |
| 688 |
* The visual parameter, is based on GDK_WA_VISUAL if set already. |
| 689 |
* From attributes the only things used is: colormap, title, |
| 690 |
* wmclass and type_hint. [1]. We are checking redundant information |
| 691 |
* and complain if that changes, which would break this implementation |
| 692 |
* again. |
| 693 |
* |
| 694 |
* [1] http://mail.gnome.org/archives/gtk-devel-list/2010-August/msg00214.html |
| 695 |
*/ |
| 696 |
void |
| 697 |
_gdk_win32_display_create_window_impl (GdkDisplay *display, |
| 698 |
GdkWindow *window, |
| 699 |
GdkWindow *real_parent, |
| 700 |
GdkScreen *screen, |
| 701 |
GdkEventMask event_mask, |
| 702 |
GdkWindowAttr *attributes, |
| 703 |
gint attributes_mask) |
| 704 |
{ |
| 705 |
HWND hwndNew; |
| 706 |
HANDLE hparent; |
| 707 |
ATOM klass = 0; |
| 708 |
DWORD dwStyle = 0, dwExStyle; |
| 709 |
RECT rect; |
| 710 |
GdkWindowImplWin32 *impl; |
| 711 |
GdkWin32Display *display_win32; |
| 712 |
const gchar *title; |
| 713 |
wchar_t *wtitle; |
| 714 |
gboolean override_redirect; |
| 715 |
gint window_width, window_height; |
| 716 |
gint offset_x = 0, offset_y = 0; |
| 717 |
gint x, y, real_x = 0, real_y = 0; |
| 718 |
/* check consistency of redundant information */ |
| 719 |
guint remaining_mask = attributes_mask; |
| 720 |
|
| 721 |
g_return_if_fail (display == _gdk_display); |
| 722 |
|
| 723 |
GDK_NOTE (MISC, |
| 724 |
g_print ("_gdk_window_impl_new: %s %s\n", |
| 725 |
(window->window_type == GDK_WINDOW_TOPLEVEL ? "TOPLEVEL" : |
| 726 |
(window->window_type == GDK_WINDOW_CHILD ? "CHILD" : |
| 727 |
(window->window_type == GDK_WINDOW_TEMP ? "TEMP" : |
| 728 |
"???"))), |
| 729 |
(attributes->wclass == GDK_INPUT_OUTPUT ? "" : "input-only")) |
| 730 |
); |
| 731 |
|
| 732 |
/* to ensure to not miss important information some additional check against |
| 733 |
* attributes which may silently work on X11 */ |
| 734 |
if ((attributes_mask & GDK_WA_X) != 0) |
| 735 |
{ |
| 736 |
g_assert (attributes->x == window->x); |
| 737 |
remaining_mask &= ~GDK_WA_X; |
| 738 |
} |
| 739 |
if ((attributes_mask & GDK_WA_Y) != 0) |
| 740 |
{ |
| 741 |
g_assert (attributes->y == window->y); |
| 742 |
remaining_mask &= ~GDK_WA_Y; |
| 743 |
} |
| 744 |
override_redirect = FALSE; |
| 745 |
if ((attributes_mask & GDK_WA_NOREDIR) != 0) |
| 746 |
{ |
| 747 |
override_redirect = !!attributes->override_redirect; |
| 748 |
remaining_mask &= ~GDK_WA_NOREDIR; |
| 749 |
} |
| 750 |
|
| 751 |
if ((remaining_mask & ~(GDK_WA_WMCLASS|GDK_WA_VISUAL|GDK_WA_CURSOR|GDK_WA_TITLE|GDK_WA_TYPE_HINT)) != 0) |
| 752 |
g_warning ("_gdk_window_impl_new: uexpected attribute 0x%X", |
| 753 |
remaining_mask & ~(GDK_WA_WMCLASS|GDK_WA_VISUAL|GDK_WA_CURSOR|GDK_WA_TITLE|GDK_WA_TYPE_HINT)); |
| 754 |
|
| 755 |
hparent = GDK_WINDOW_HWND (real_parent); |
| 756 |
|
| 757 |
impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WIN32, NULL); |
| 758 |
impl->wrapper = GDK_WINDOW (window); |
| 759 |
window->impl = GDK_WINDOW_IMPL (impl); |
| 760 |
|
| 761 |
if (attributes_mask & GDK_WA_VISUAL) |
| 762 |
g_assert ((gdk_screen_get_system_visual (screen) == attributes->visual) || |
| 763 |
(gdk_screen_get_rgba_visual (screen) == attributes->visual)); |
| 764 |
|
| 765 |
impl->override_redirect = override_redirect; |
| 766 |
impl->layered = FALSE; |
| 767 |
impl->layered_opacity = 1.0; |
| 768 |
|
| 769 |
display_win32 = GDK_WIN32_DISPLAY (display); |
| 770 |
impl->window_scale = _gdk_win32_display_get_monitor_scale_factor (display_win32, NULL, NULL, NULL); |
| 771 |
impl->unscaled_width = window->width * impl->window_scale; |
| 772 |
impl->unscaled_height = window->height * impl->window_scale; |
| 773 |
|
| 774 |
/* wclass is not any longer set always, but if is ... */ |
| 775 |
if ((attributes_mask & GDK_WA_WMCLASS) == GDK_WA_WMCLASS) |
| 776 |
g_assert ((attributes->wclass == GDK_INPUT_OUTPUT) == !window->input_only); |
| 777 |
|
| 778 |
if (!window->input_only) |
| 779 |
{ |
| 780 |
dwExStyle = 0; |
| 781 |
} |
| 782 |
else |
| 783 |
{ |
| 784 |
/* I very much doubt using WS_EX_TRANSPARENT actually |
| 785 |
* corresponds to how X11 InputOnly windows work, but it appears |
| 786 |
* to work well enough for the actual use cases in gtk. |
| 787 |
*/ |
| 788 |
dwExStyle = WS_EX_TRANSPARENT; |
| 789 |
GDK_NOTE (MISC, g_print ("... GDK_INPUT_ONLY\n")); |
| 790 |
} |
| 791 |
|
| 792 |
switch (window->window_type) |
| 793 |
{ |
| 794 |
case GDK_WINDOW_TOPLEVEL: |
| 795 |
if (GDK_WINDOW_TYPE (window->parent) != GDK_WINDOW_ROOT) |
| 796 |
{ |
| 797 |
/* The common code warns for this case. */ |
| 798 |
hparent = GetDesktopWindow (); |
| 799 |
} |
| 800 |
/* Children of foreign windows aren't toplevel windows */ |
| 801 |
if (GDK_WINDOW_TYPE (real_parent) == GDK_WINDOW_FOREIGN) |
| 802 |
{ |
| 803 |
dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN; |
| 804 |
} |
| 805 |
else |
| 806 |
{ |
| 807 |
/* MSDN: We need WS_CLIPCHILDREN and WS_CLIPSIBLINGS for GL Context Creation */ |
| 808 |
dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 809 |
|
| 810 |
offset_x = _gdk_offset_x; |
| 811 |
offset_y = _gdk_offset_y; |
| 812 |
} |
| 813 |
break; |
| 814 |
|
| 815 |
case GDK_WINDOW_CHILD: |
| 816 |
dwStyle = WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 817 |
break; |
| 818 |
|
| 819 |
case GDK_WINDOW_TEMP: |
| 820 |
/* A temp window is not necessarily a top level window */ |
| 821 |
dwStyle = (gdk_screen_get_root_window (screen) == real_parent ? WS_POPUP : WS_CHILDWINDOW); |
| 822 |
dwStyle |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 823 |
dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST; |
| 824 |
offset_x = _gdk_offset_x; |
| 825 |
offset_y = _gdk_offset_y; |
| 826 |
break; |
| 827 |
|
| 828 |
default: |
| 829 |
g_assert_not_reached (); |
| 830 |
} |
| 831 |
|
| 832 |
if (attributes_mask & GDK_WA_TYPE_HINT) |
| 833 |
gdk_window_set_type_hint (window, attributes->type_hint); |
| 834 |
|
| 835 |
if (impl->type_hint != GDK_WINDOW_TYPE_HINT_NORMAL) |
| 836 |
dwStyle &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX); |
| 837 |
|
| 838 |
if (window->window_type != GDK_WINDOW_CHILD) |
| 839 |
{ |
| 840 |
rect.left = window->x * impl->window_scale; |
| 841 |
rect.top = window->y * impl->window_scale; |
| 842 |
rect.right = rect.left + window->width * impl->window_scale; |
| 843 |
rect.bottom = rect.top + window->height * impl->window_scale; |
| 844 |
|
| 845 |
AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle); |
| 846 |
|
| 847 |
real_x = window->x * impl->window_scale - offset_x; |
| 848 |
real_y = window->y * impl->window_scale - offset_y; |
| 849 |
|
| 850 |
if (window->window_type == GDK_WINDOW_TOPLEVEL) |
| 851 |
{ |
| 852 |
/* We initially place it at default so that we can get the |
| 853 |
default window positioning if we want */ |
| 854 |
x = y = CW_USEDEFAULT; |
| 855 |
} |
| 856 |
else |
| 857 |
{ |
| 858 |
/* TEMP, FOREIGN: Put these where requested */ |
| 859 |
x = real_x; |
| 860 |
y = real_y; |
| 861 |
} |
| 862 |
|
| 863 |
window_width = rect.right - rect.left; |
| 864 |
window_height = rect.bottom - rect.top; |
| 865 |
} |
| 866 |
else |
| 867 |
{ |
| 868 |
/* adjust position relative to real_parent */ |
| 869 |
window_width = impl->unscaled_width; |
| 870 |
window_height = impl->unscaled_height; |
| 871 |
/* use given position for initial placement, native coordinates */ |
| 872 |
x = (window->x + window->parent->abs_x) * impl->window_scale; |
| 873 |
y = (window->y + window->parent->abs_y) * impl->window_scale; |
| 874 |
} |
| 875 |
|
| 876 |
if (attributes_mask & GDK_WA_TITLE) |
| 877 |
title = attributes->title; |
| 878 |
else |
| 879 |
title = get_default_title (); |
| 880 |
if (!title || !*title) |
| 881 |
title = ""; |
| 882 |
|
| 883 |
impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask; |
| 884 |
|
| 885 |
if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY) |
| 886 |
dwExStyle |= WS_EX_TOOLWINDOW; |
| 887 |
|
| 888 |
/* WS_EX_LAYERED | WS_EX_TRANSPARENT makes the window transparent w.r.t. |
| 889 |
* pointer input: the system will direct all pointer input to the window |
| 890 |
* below. We don't want a DND indicator to accept pointer input, because |
| 891 |
* that will make it a potential drop target. |
| 892 |
*/ |
| 893 |
if (impl->type_hint == GDK_WINDOW_TYPE_HINT_DND) |
| 894 |
dwExStyle |= WS_EX_LAYERED | WS_EX_TRANSPARENT; |
| 895 |
|
| 896 |
klass = RegisterGdkClass (window->window_type, impl->type_hint); |
| 897 |
|
| 898 |
wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL); |
| 899 |
|
| 900 |
hwndNew = CreateWindowExW (dwExStyle, |
| 901 |
MAKEINTRESOURCEW (klass), |
| 902 |
wtitle, |
| 903 |
dwStyle, |
| 904 |
x, |
| 905 |
y, |
| 906 |
window_width, window_height, |
| 907 |
hparent, |
| 908 |
NULL, |
| 909 |
_gdk_app_hmodule, |
| 910 |
window); |
| 911 |
if (GDK_WINDOW_HWND (window) != hwndNew) |
| 912 |
{ |
| 913 |
g_warning ("gdk_window_new: gdk_event_translate::WM_CREATE (%p, %p) HWND mismatch.", |
| 914 |
GDK_WINDOW_HWND (window), |
| 915 |
hwndNew); |
| 916 |
|
| 917 |
/* HB: IHMO due to a race condition the handle was increased by |
| 918 |
* one, which causes much trouble. Because I can't find the |
| 919 |
* real bug, try to workaround it ... |
| 920 |
* To reproduce: compile with MSVC 5, DEBUG=1 |
| 921 |
*/ |
| 922 |
# if 0 |
| 923 |
gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window)); |
| 924 |
GDK_WINDOW_HWND (window) = hwndNew; |
| 925 |
gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window); |
| 926 |
# else |
| 927 |
/* the old behaviour, but with warning */ |
| 928 |
impl->handle = hwndNew; |
| 929 |
# endif |
| 930 |
|
| 931 |
} |
| 932 |
|
| 933 |
if (window->window_type != GDK_WINDOW_CHILD) |
| 934 |
{ |
| 935 |
GetWindowRect (GDK_WINDOW_HWND (window), &rect); |
| 936 |
impl->initial_x = rect.left; |
| 937 |
impl->initial_y = rect.top; |
| 938 |
|
| 939 |
/* Now we know the initial position, move to actually specified position */ |
| 940 |
if (real_x != x || real_y != y) |
| 941 |
{ |
| 942 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 943 |
SWP_NOZORDER_SPECIFIED, |
| 944 |
real_x, real_y, 0, 0, |
| 945 |
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
g_object_ref (window); |
| 950 |
gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window); |
| 951 |
|
| 952 |
GDK_NOTE (MISC, g_print ("... \"%s\" %dx%d@%+d%+d %p = %p\n", |
| 953 |
title, |
| 954 |
window_width, window_height, |
| 955 |
window->x, |
| 956 |
window->y, |
| 957 |
hparent, |
| 958 |
GDK_WINDOW_HWND (window))); |
| 959 |
|
| 960 |
/* Add window handle to title */ |
| 961 |
GDK_NOTE (MISC_OR_EVENTS, gdk_window_set_title (window, title)); |
| 962 |
|
| 963 |
g_free (wtitle); |
| 964 |
|
| 965 |
if (impl->handle == NULL) |
| 966 |
{ |
| 967 |
WIN32_API_FAILED ("CreateWindowExW"); |
| 968 |
g_object_unref (window); |
| 969 |
return; |
| 970 |
} |
| 971 |
|
| 972 |
// if (!from_set_skip_taskbar_hint && window->window_type == GDK_WINDOW_TEMP) |
| 973 |
// gdk_window_set_skip_taskbar_hint (window, TRUE); |
| 974 |
|
| 975 |
if (attributes_mask & GDK_WA_CURSOR) |
| 976 |
gdk_window_set_cursor (window, attributes->cursor); |
| 977 |
|
| 978 |
if (_gdk_win32_tablet_input_api == GDK_WIN32_TABLET_INPUT_API_WINPOINTER) |
| 979 |
gdk_winpointer_initialize_window (window); |
| 980 |
|
| 981 |
_gdk_win32_window_enable_transparency (window); |
| 982 |
} |
| 983 |
|
| 984 |
GdkWindow * |
| 985 |
gdk_win32_window_foreign_new_for_display (GdkDisplay *display, |
| 986 |
HWND anid) |
| 987 |
{ |
| 988 |
GdkWindow *window; |
| 989 |
GdkWindowImplWin32 *impl; |
| 990 |
|
| 991 |
HANDLE parent; |
| 992 |
RECT rect; |
| 993 |
POINT point; |
| 994 |
|
| 995 |
if ((window = gdk_win32_window_lookup_for_display (display, anid)) != NULL) |
| 996 |
return g_object_ref (window); |
| 997 |
|
| 998 |
window = _gdk_display_create_window (display); |
| 999 |
window->visual = gdk_screen_get_system_visual (gdk_display_get_default_screen (display)); |
| 1000 |
window->impl = g_object_new (GDK_TYPE_WINDOW_IMPL_WIN32, NULL); |
| 1001 |
window->impl_window = window; |
| 1002 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1003 |
impl->wrapper = window; |
| 1004 |
parent = GetParent (anid); |
| 1005 |
|
| 1006 |
window->parent = gdk_win32_handle_table_lookup (parent); |
| 1007 |
if (!window->parent || GDK_WINDOW_TYPE (window->parent) == GDK_WINDOW_FOREIGN) |
| 1008 |
window->parent = gdk_get_default_root_window (); |
| 1009 |
|
| 1010 |
window->parent->children = g_list_concat (&window->children_list_node, window->parent->children); |
| 1011 |
window->parent->impl_window->native_children = |
| 1012 |
g_list_prepend (window->parent->impl_window->native_children, window); |
| 1013 |
|
| 1014 |
GetClientRect ((HWND) anid, &rect); |
| 1015 |
point.x = rect.left; |
| 1016 |
point.y = rect.right; |
| 1017 |
ClientToScreen ((HWND) anid, &point); |
| 1018 |
if (parent != GetDesktopWindow ()) |
| 1019 |
ScreenToClient (parent, &point); |
| 1020 |
window->x = point.x / impl->window_scale; |
| 1021 |
window->y = point.y / impl->window_scale; |
| 1022 |
impl->unscaled_width = rect.right - rect.left; |
| 1023 |
impl->unscaled_height = rect.bottom - rect.top; |
| 1024 |
window->width = (impl->unscaled_width + impl->window_scale - 1) / impl->window_scale; |
| 1025 |
window->height = (impl->unscaled_height + impl->window_scale - 1) / impl->window_scale; |
| 1026 |
window->window_type = GDK_WINDOW_FOREIGN; |
| 1027 |
window->destroyed = FALSE; |
| 1028 |
window->event_mask = GDK_ALL_EVENTS_MASK; /* XXX */ |
| 1029 |
if (IsWindowVisible ((HWND) anid)) |
| 1030 |
window->state &= (~GDK_WINDOW_STATE_WITHDRAWN); |
| 1031 |
else |
| 1032 |
window->state |= GDK_WINDOW_STATE_WITHDRAWN; |
| 1033 |
if (GetWindowLong ((HWND)anid, GWL_EXSTYLE) & WS_EX_TOPMOST) |
| 1034 |
window->state |= GDK_WINDOW_STATE_ABOVE; |
| 1035 |
else |
| 1036 |
window->state &= (~GDK_WINDOW_STATE_ABOVE); |
| 1037 |
window->state &= (~GDK_WINDOW_STATE_BELOW); |
| 1038 |
window->viewable = TRUE; |
| 1039 |
|
| 1040 |
window->depth = gdk_visual_get_system ()->depth; |
| 1041 |
GDK_WINDOW_HWND (window) = anid; |
| 1042 |
|
| 1043 |
g_object_ref (window); |
| 1044 |
gdk_win32_handle_table_insert (&GDK_WINDOW_HWND (window), window); |
| 1045 |
|
| 1046 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_foreign_new_for_display: %p: %s@%+d%+d\n", |
| 1047 |
(HWND) anid, |
| 1048 |
_gdk_win32_window_description (window), |
| 1049 |
window->x, window->y)); |
| 1050 |
|
| 1051 |
return window; |
| 1052 |
} |
| 1053 |
|
| 1054 |
static void |
| 1055 |
gdk_win32_window_destroy (GdkWindow *window, |
| 1056 |
gboolean recursing, |
| 1057 |
gboolean foreign_destroy) |
| 1058 |
{ |
| 1059 |
GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1060 |
GSList *tmp; |
| 1061 |
GdkWin32Display *display = NULL; |
| 1062 |
|
| 1063 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1064 |
|
| 1065 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_destroy: %p\n", |
| 1066 |
GDK_WINDOW_HWND (window))); |
| 1067 |
|
| 1068 |
/* Remove ourself from the modal stack */ |
| 1069 |
_gdk_remove_modal_window (window); |
| 1070 |
|
| 1071 |
/* Remove all our transient children */ |
| 1072 |
while (window_impl->transient_children != NULL) |
| 1073 |
{ |
| 1074 |
GdkWindow *child = window_impl->transient_children->data; |
| 1075 |
gdk_window_set_transient_for (child, NULL); |
| 1076 |
} |
| 1077 |
|
| 1078 |
#ifdef GDK_WIN32_ENABLE_EGL |
| 1079 |
display = GDK_WIN32_DISPLAY (gdk_window_get_display (window)); |
| 1080 |
|
| 1081 |
/* Get rid of any EGLSurfaces that we might have created */ |
| 1082 |
if (window_impl->egl_surface != EGL_NO_SURFACE) |
| 1083 |
{ |
| 1084 |
eglDestroySurface (display->egl_disp, window_impl->egl_surface); |
| 1085 |
window_impl->egl_surface = EGL_NO_SURFACE; |
| 1086 |
} |
| 1087 |
if (window_impl->egl_dummy_surface != EGL_NO_SURFACE) |
| 1088 |
{ |
| 1089 |
eglDestroySurface (display->egl_disp, window_impl->egl_dummy_surface); |
| 1090 |
window_impl->egl_dummy_surface = EGL_NO_SURFACE; |
| 1091 |
} |
| 1092 |
#endif |
| 1093 |
|
| 1094 |
/* Remove ourself from our transient owner */ |
| 1095 |
if (window_impl->transient_owner != NULL) |
| 1096 |
{ |
| 1097 |
gdk_window_set_transient_for (window, NULL); |
| 1098 |
} |
| 1099 |
|
| 1100 |
if (!recursing && !foreign_destroy) |
| 1101 |
{ |
| 1102 |
window->destroyed = TRUE; |
| 1103 |
DestroyWindow (GDK_WINDOW_HWND (window)); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
static void |
| 1108 |
gdk_win32_window_destroy_foreign (GdkWindow *window) |
| 1109 |
{ |
| 1110 |
/* It's somebody else's window, but in our hierarchy, so reparent it |
| 1111 |
* to the desktop, and then try to destroy it. |
| 1112 |
*/ |
| 1113 |
gdk_window_hide (window); |
| 1114 |
gdk_window_reparent (window, NULL, 0, 0); |
| 1115 |
|
| 1116 |
PostMessage (GDK_WINDOW_HWND (window), WM_CLOSE, 0, 0); |
| 1117 |
} |
| 1118 |
|
| 1119 |
/* This function is called when the window really gone. |
| 1120 |
*/ |
| 1121 |
static void |
| 1122 |
gdk_win32_window_destroy_notify (GdkWindow *window) |
| 1123 |
{ |
| 1124 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1125 |
|
| 1126 |
GDK_NOTE (EVENTS, |
| 1127 |
g_print ("gdk_window_destroy_notify: %p%s\n", |
| 1128 |
GDK_WINDOW_HWND (window), |
| 1129 |
(GDK_WINDOW_DESTROYED (window) ? " (destroyed)" : ""))); |
| 1130 |
|
| 1131 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 1132 |
{ |
| 1133 |
if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN) |
| 1134 |
g_warning ("window %p unexpectedly destroyed", |
| 1135 |
GDK_WINDOW_HWND (window)); |
| 1136 |
|
| 1137 |
_gdk_window_destroy (window, TRUE); |
| 1138 |
} |
| 1139 |
|
| 1140 |
gdk_win32_handle_table_remove (GDK_WINDOW_HWND (window)); |
| 1141 |
g_object_unref (window); |
| 1142 |
} |
| 1143 |
|
| 1144 |
static void |
| 1145 |
get_outer_rect (GdkWindow *window, |
| 1146 |
gint width, |
| 1147 |
gint height, |
| 1148 |
RECT *rect) |
| 1149 |
{ |
| 1150 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1151 |
|
| 1152 |
rect->left = rect->top = 0; |
| 1153 |
rect->right = width * impl->window_scale; |
| 1154 |
rect->bottom = height * impl->window_scale; |
| 1155 |
|
| 1156 |
_gdk_win32_adjust_client_rect (window, rect); |
| 1157 |
} |
| 1158 |
|
| 1159 |
static void |
| 1160 |
adjust_for_gravity_hints (GdkWindow *window, |
| 1161 |
RECT *outer_rect, |
| 1162 |
gint *x, |
| 1163 |
gint *y) |
| 1164 |
{ |
| 1165 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1166 |
|
| 1167 |
if (impl->hint_flags & GDK_HINT_WIN_GRAVITY) |
| 1168 |
{ |
| 1169 |
#ifdef G_ENABLE_DEBUG |
| 1170 |
gint orig_x = *x, orig_y = *y; |
| 1171 |
#endif |
| 1172 |
|
| 1173 |
switch (impl->hints.win_gravity) |
| 1174 |
{ |
| 1175 |
case GDK_GRAVITY_NORTH: |
| 1176 |
case GDK_GRAVITY_CENTER: |
| 1177 |
case GDK_GRAVITY_SOUTH: |
| 1178 |
*x -= (outer_rect->right - outer_rect->left / 2) / impl->window_scale; |
| 1179 |
*x += window->width / 2; |
| 1180 |
break; |
| 1181 |
|
| 1182 |
case GDK_GRAVITY_SOUTH_EAST: |
| 1183 |
case GDK_GRAVITY_EAST: |
| 1184 |
case GDK_GRAVITY_NORTH_EAST: |
| 1185 |
*x -= (outer_rect->right - outer_rect->left) / impl->window_scale; |
| 1186 |
*x += window->width; |
| 1187 |
break; |
| 1188 |
|
| 1189 |
case GDK_GRAVITY_STATIC: |
| 1190 |
*x += outer_rect->left / impl->window_scale; |
| 1191 |
break; |
| 1192 |
|
| 1193 |
default: |
| 1194 |
break; |
| 1195 |
} |
| 1196 |
|
| 1197 |
switch (impl->hints.win_gravity) |
| 1198 |
{ |
| 1199 |
case GDK_GRAVITY_WEST: |
| 1200 |
case GDK_GRAVITY_CENTER: |
| 1201 |
case GDK_GRAVITY_EAST: |
| 1202 |
*y -= ((outer_rect->bottom - outer_rect->top) / 2) / impl->window_scale; |
| 1203 |
*y += window->height / 2; |
| 1204 |
break; |
| 1205 |
|
| 1206 |
case GDK_GRAVITY_SOUTH_WEST: |
| 1207 |
case GDK_GRAVITY_SOUTH: |
| 1208 |
case GDK_GRAVITY_SOUTH_EAST: |
| 1209 |
*y -= (outer_rect->bottom - outer_rect->top) / impl->window_scale; |
| 1210 |
*y += window->height; |
| 1211 |
break; |
| 1212 |
|
| 1213 |
case GDK_GRAVITY_STATIC: |
| 1214 |
*y += outer_rect->top * impl->window_scale; |
| 1215 |
break; |
| 1216 |
|
| 1217 |
default: |
| 1218 |
break; |
| 1219 |
} |
| 1220 |
GDK_NOTE (MISC, |
| 1221 |
(orig_x != *x || orig_y != *y) ? |
| 1222 |
g_print ("adjust_for_gravity_hints: x: %d->%d, y: %d->%d\n", |
| 1223 |
orig_x, *x, orig_y, *y) |
| 1224 |
: (void) 0); |
| 1225 |
} |
| 1226 |
} |
| 1227 |
|
| 1228 |
static void |
| 1229 |
show_window_internal (GdkWindow *window, |
| 1230 |
gboolean already_mapped, |
| 1231 |
gboolean deiconify) |
| 1232 |
{ |
| 1233 |
GdkWindowImplWin32 *window_impl; |
| 1234 |
gboolean focus_on_map = FALSE; |
| 1235 |
DWORD exstyle; |
| 1236 |
|
| 1237 |
if (window->destroyed) |
| 1238 |
return; |
| 1239 |
|
| 1240 |
GDK_NOTE (MISC, g_print ("show_window_internal: %p: %s%s\n", |
| 1241 |
GDK_WINDOW_HWND (window), |
| 1242 |
_gdk_win32_window_state_to_string (window->state), |
| 1243 |
(deiconify ? " deiconify" : ""))); |
| 1244 |
|
| 1245 |
/* If asked to show (not deiconify) an withdrawn and iconified |
| 1246 |
* window, do that. |
| 1247 |
*/ |
| 1248 |
if (!deiconify && |
| 1249 |
!already_mapped && |
| 1250 |
(window->state & GDK_WINDOW_STATE_ICONIFIED)) |
| 1251 |
{ |
| 1252 |
GtkShowWindow (window, SW_SHOWMINNOACTIVE); |
| 1253 |
return; |
| 1254 |
} |
| 1255 |
|
| 1256 |
/* If asked to just show an iconified window, do nothing. */ |
| 1257 |
if (!deiconify && (window->state & GDK_WINDOW_STATE_ICONIFIED)) |
| 1258 |
return; |
| 1259 |
|
| 1260 |
/* If asked to deiconify an already noniconified window, do |
| 1261 |
* nothing. (Especially, don't cause the window to rise and |
| 1262 |
* activate. There are different calls for that.) |
| 1263 |
*/ |
| 1264 |
if (deiconify && !(window->state & GDK_WINDOW_STATE_ICONIFIED)) |
| 1265 |
return; |
| 1266 |
|
| 1267 |
/* If asked to show (but not raise) a window that is already |
| 1268 |
* visible, do nothing. |
| 1269 |
*/ |
| 1270 |
if (!deiconify && !already_mapped && IsWindowVisible (GDK_WINDOW_HWND (window))) |
| 1271 |
return; |
| 1272 |
|
| 1273 |
/* Other cases */ |
| 1274 |
|
| 1275 |
if (!already_mapped) |
| 1276 |
focus_on_map = window->focus_on_map; |
| 1277 |
|
| 1278 |
exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE); |
| 1279 |
|
| 1280 |
/* If we have to show an input-only window, |
| 1281 |
* redraws can be safely skipped. |
| 1282 |
*/ |
| 1283 |
if (window->input_only) |
| 1284 |
{ |
| 1285 |
UINT flags = SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER; |
| 1286 |
|
| 1287 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP || !focus_on_map) |
| 1288 |
flags |= SWP_NOACTIVATE; |
| 1289 |
|
| 1290 |
SetWindowPos (GDK_WINDOW_HWND (window), |
| 1291 |
SWP_NOZORDER_SPECIFIED, 0, 0, 0, 0, flags); |
| 1292 |
|
| 1293 |
return; |
| 1294 |
} |
| 1295 |
|
| 1296 |
/* For initial map of "normal" windows we want to emulate WM window |
| 1297 |
* positioning behaviour, which means: |
| 1298 |
* + Use user specified position if GDK_HINT_POS or GDK_HINT_USER_POS |
| 1299 |
* otherwise: |
| 1300 |
* + default to the initial CW_USEDEFAULT placement, |
| 1301 |
* no matter if the user moved the window before showing it. |
| 1302 |
* + Certain window types and hints have more elaborate positioning |
| 1303 |
* schemes. |
| 1304 |
*/ |
| 1305 |
window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1306 |
if (!already_mapped && |
| 1307 |
GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL && |
| 1308 |
(window_impl->hint_flags & (GDK_HINT_POS | GDK_HINT_USER_POS)) == 0 && |
| 1309 |
!window_impl->override_redirect) |
| 1310 |
{ |
| 1311 |
gboolean center = FALSE; |
| 1312 |
RECT window_rect, center_on_rect; |
| 1313 |
int x, y; |
| 1314 |
|
| 1315 |
x = window_impl->initial_x; |
| 1316 |
y = window_impl->initial_y; |
| 1317 |
|
| 1318 |
if (window_impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN) |
| 1319 |
{ |
| 1320 |
HMONITOR monitor; |
| 1321 |
MONITORINFO mi; |
| 1322 |
|
| 1323 |
monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST); |
| 1324 |
mi.cbSize = sizeof (mi); |
| 1325 |
if (monitor && GetMonitorInfo (monitor, &mi)) |
| 1326 |
center_on_rect = mi.rcMonitor; |
| 1327 |
else |
| 1328 |
{ |
| 1329 |
center_on_rect.left = 0; |
| 1330 |
center_on_rect.top = 0; |
| 1331 |
center_on_rect.right = GetSystemMetrics (SM_CXSCREEN); |
| 1332 |
center_on_rect.bottom = GetSystemMetrics (SM_CYSCREEN); |
| 1333 |
} |
| 1334 |
center = TRUE; |
| 1335 |
} |
| 1336 |
else if (window_impl->transient_owner != NULL && |
| 1337 |
GDK_WINDOW_IS_MAPPED (window_impl->transient_owner)) |
| 1338 |
{ |
| 1339 |
GdkWindow *owner = window_impl->transient_owner; |
| 1340 |
/* Center on transient parent */ |
| 1341 |
center_on_rect.left = owner->x * window_impl->window_scale - _gdk_offset_x; |
| 1342 |
center_on_rect.top = owner->y * window_impl->window_scale - _gdk_offset_y; |
| 1343 |
center_on_rect.right = center_on_rect.left + owner->width * window_impl->window_scale; |
| 1344 |
center_on_rect.bottom = center_on_rect.top + owner->height * window_impl->window_scale; |
| 1345 |
|
| 1346 |
_gdk_win32_adjust_client_rect (GDK_WINDOW (owner), ¢er_on_rect); |
| 1347 |
center = TRUE; |
| 1348 |
} |
| 1349 |
|
| 1350 |
if (center) |
| 1351 |
{ |
| 1352 |
window_rect.left = 0; |
| 1353 |
window_rect.top = 0; |
| 1354 |
window_rect.right = window->width * window_impl->window_scale; |
| 1355 |
window_rect.bottom = window->height * window_impl->window_scale; |
| 1356 |
_gdk_win32_adjust_client_rect (window, &window_rect); |
| 1357 |
|
| 1358 |
x = center_on_rect.left + ((center_on_rect.right - center_on_rect.left) - (window_rect.right - window_rect.left)) / 2; |
| 1359 |
y = center_on_rect.top + ((center_on_rect.bottom - center_on_rect.top) - (window_rect.bottom - window_rect.top)) / 2; |
| 1360 |
} |
| 1361 |
|
| 1362 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1363 |
SWP_NOZORDER_SPECIFIED, |
| 1364 |
x, y, 0, 0, |
| 1365 |
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); |
| 1366 |
} |
| 1367 |
|
| 1368 |
if (!already_mapped && |
| 1369 |
GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL && |
| 1370 |
!window_impl->override_redirect) |
| 1371 |
{ |
| 1372 |
/* Ensure new windows are fully onscreen */ |
| 1373 |
RECT window_rect; |
| 1374 |
HMONITOR monitor; |
| 1375 |
MONITORINFO mi; |
| 1376 |
int x, y; |
| 1377 |
|
| 1378 |
GetWindowRect (GDK_WINDOW_HWND (window), &window_rect); |
| 1379 |
|
| 1380 |
monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST); |
| 1381 |
mi.cbSize = sizeof (mi); |
| 1382 |
if (monitor && GetMonitorInfo (monitor, &mi)) |
| 1383 |
{ |
| 1384 |
x = window_rect.left; |
| 1385 |
y = window_rect.top; |
| 1386 |
|
| 1387 |
if (window_rect.right > mi.rcWork.right) |
| 1388 |
{ |
| 1389 |
window_rect.left -= (window_rect.right - mi.rcWork.right); |
| 1390 |
window_rect.right -= (window_rect.right - mi.rcWork.right); |
| 1391 |
} |
| 1392 |
|
| 1393 |
if (window_rect.bottom > mi.rcWork.bottom) |
| 1394 |
{ |
| 1395 |
window_rect.top -= (window_rect.bottom - mi.rcWork.bottom); |
| 1396 |
window_rect.bottom -= (window_rect.bottom - mi.rcWork.bottom); |
| 1397 |
} |
| 1398 |
|
| 1399 |
if (window_rect.left < mi.rcWork.left) |
| 1400 |
{ |
| 1401 |
window_rect.right += (mi.rcWork.left - window_rect.left); |
| 1402 |
window_rect.left += (mi.rcWork.left - window_rect.left); |
| 1403 |
} |
| 1404 |
|
| 1405 |
if (window_rect.top < mi.rcWork.top) |
| 1406 |
{ |
| 1407 |
window_rect.bottom += (mi.rcWork.top - window_rect.top); |
| 1408 |
window_rect.top += (mi.rcWork.top - window_rect.top); |
| 1409 |
} |
| 1410 |
|
| 1411 |
if (x != window_rect.left || y != window_rect.top) |
| 1412 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1413 |
SWP_NOZORDER_SPECIFIED, |
| 1414 |
window_rect.left, window_rect.top, 0, 0, |
| 1415 |
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
|
| 1419 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 1420 |
{ |
| 1421 |
gdk_window_fullscreen (window); |
| 1422 |
} |
| 1423 |
else if (window->state & GDK_WINDOW_STATE_MAXIMIZED) |
| 1424 |
{ |
| 1425 |
GtkShowWindow (window, SW_MAXIMIZE); |
| 1426 |
} |
| 1427 |
else if (window->state & GDK_WINDOW_STATE_ICONIFIED) |
| 1428 |
{ |
| 1429 |
if (focus_on_map) |
| 1430 |
GtkShowWindow (window, SW_RESTORE); |
| 1431 |
else |
| 1432 |
GtkShowWindow (window, SW_SHOWNOACTIVATE); |
| 1433 |
} |
| 1434 |
else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP || !focus_on_map) |
| 1435 |
{ |
| 1436 |
if (!IsWindowVisible (GDK_WINDOW_HWND (window))) |
| 1437 |
GtkShowWindow (window, SW_SHOWNOACTIVATE); |
| 1438 |
else |
| 1439 |
GtkShowWindow (window, SW_SHOWNA); |
| 1440 |
} |
| 1441 |
else if (!IsWindowVisible (GDK_WINDOW_HWND (window))) |
| 1442 |
{ |
| 1443 |
GtkShowWindow (window, SW_SHOWNORMAL); |
| 1444 |
} |
| 1445 |
else |
| 1446 |
{ |
| 1447 |
GtkShowWindow (window, SW_SHOW); |
| 1448 |
} |
| 1449 |
|
| 1450 |
/* Sync STATE_ABOVE to TOPMOST */ |
| 1451 |
if (GDK_WINDOW_TYPE (window) != GDK_WINDOW_TEMP && |
| 1452 |
(((window->state & GDK_WINDOW_STATE_ABOVE) && |
| 1453 |
!(exstyle & WS_EX_TOPMOST)) || |
| 1454 |
(!(window->state & GDK_WINDOW_STATE_ABOVE) && |
| 1455 |
(exstyle & WS_EX_TOPMOST)))) |
| 1456 |
{ |
| 1457 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1458 |
(window->state & GDK_WINDOW_STATE_ABOVE)?HWND_TOPMOST:HWND_NOTOPMOST, |
| 1459 |
0, 0, 0, 0, |
| 1460 |
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE)); |
| 1461 |
} |
| 1462 |
} |
| 1463 |
|
| 1464 |
static void |
| 1465 |
gdk_win32_window_show (GdkWindow *window, |
| 1466 |
gboolean already_mapped) |
| 1467 |
{ |
| 1468 |
show_window_internal (window, FALSE, FALSE); |
| 1469 |
} |
| 1470 |
|
| 1471 |
static void |
| 1472 |
gdk_win32_window_hide (GdkWindow *window) |
| 1473 |
{ |
| 1474 |
if (window->destroyed) |
| 1475 |
return; |
| 1476 |
|
| 1477 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_hide: %p: %s\n", |
| 1478 |
GDK_WINDOW_HWND (window), |
| 1479 |
_gdk_win32_window_state_to_string (window->state))); |
| 1480 |
|
| 1481 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 1482 |
gdk_synthesize_window_state (window, |
| 1483 |
0, |
| 1484 |
GDK_WINDOW_STATE_WITHDRAWN); |
| 1485 |
|
| 1486 |
_gdk_window_clear_update_area (window); |
| 1487 |
|
| 1488 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL) |
| 1489 |
ShowOwnedPopups (GDK_WINDOW_HWND (window), FALSE); |
| 1490 |
|
| 1491 |
/* If we have to hide an input-only window, |
| 1492 |
* readraws can be safely skipped. |
| 1493 |
*/ |
| 1494 |
if (window->input_only) |
| 1495 |
{ |
| 1496 |
SetWindowPos (GDK_WINDOW_HWND (window), SWP_NOZORDER_SPECIFIED, |
| 1497 |
0, 0, 0, 0, |
| 1498 |
SWP_HIDEWINDOW | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE); |
| 1499 |
} |
| 1500 |
else |
| 1501 |
{ |
| 1502 |
GtkShowWindow (window, SW_HIDE); |
| 1503 |
} |
| 1504 |
} |
| 1505 |
|
| 1506 |
static void |
| 1507 |
gdk_win32_window_withdraw (GdkWindow *window) |
| 1508 |
{ |
| 1509 |
if (window->destroyed) |
| 1510 |
return; |
| 1511 |
|
| 1512 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_withdraw: %p: %s\n", |
| 1513 |
GDK_WINDOW_HWND (window), |
| 1514 |
_gdk_win32_window_state_to_string (window->state))); |
| 1515 |
|
| 1516 |
gdk_window_hide (window); /* ??? */ |
| 1517 |
} |
| 1518 |
|
| 1519 |
static void |
| 1520 |
gdk_win32_window_move (GdkWindow *window, |
| 1521 |
gint x, gint y) |
| 1522 |
{ |
| 1523 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1524 |
|
| 1525 |
if (GDK_WINDOW_DESTROYED (window)) |
| 1526 |
return; |
| 1527 |
|
| 1528 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_move: %p: %+d%+d\n", |
| 1529 |
GDK_WINDOW_HWND (window), x, y)); |
| 1530 |
|
| 1531 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 1532 |
return; |
| 1533 |
|
| 1534 |
/* Don't check GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD. |
| 1535 |
* Foreign windows (another app's windows) might be children of our |
| 1536 |
* windows! Especially in the case of gtkplug/socket. |
| 1537 |
*/ |
| 1538 |
if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ()) |
| 1539 |
{ |
| 1540 |
_gdk_window_move_resize_child (window, x, y, window->width, window->height); |
| 1541 |
} |
| 1542 |
else |
| 1543 |
{ |
| 1544 |
RECT outer_rect; |
| 1545 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1546 |
|
| 1547 |
get_outer_rect (window, window->width, window->height, &outer_rect); |
| 1548 |
|
| 1549 |
adjust_for_gravity_hints (window, &outer_rect, &x, &y); |
| 1550 |
|
| 1551 |
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,0,0," |
| 1552 |
"NOACTIVATE|NOSIZE|NOZORDER)\n", |
| 1553 |
GDK_WINDOW_HWND (window), |
| 1554 |
x * impl->window_scale - _gdk_offset_x, |
| 1555 |
y * impl->window_scale - _gdk_offset_y)); |
| 1556 |
|
| 1557 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1558 |
SWP_NOZORDER_SPECIFIED, |
| 1559 |
x * impl->window_scale - _gdk_offset_x, |
| 1560 |
y * impl->window_scale - _gdk_offset_y, |
| 1561 |
0, 0, |
| 1562 |
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER)); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
|
| 1566 |
static void |
| 1567 |
gdk_win32_window_resize (GdkWindow *window, |
| 1568 |
gint width, gint height) |
| 1569 |
{ |
| 1570 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1571 |
|
| 1572 |
if (GDK_WINDOW_DESTROYED (window)) |
| 1573 |
return; |
| 1574 |
|
| 1575 |
if (width < 1) |
| 1576 |
width = 1; |
| 1577 |
if (height < 1) |
| 1578 |
height = 1; |
| 1579 |
|
| 1580 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_resize: %p: %dx%d\n", |
| 1581 |
GDK_WINDOW_HWND (window), width, height)); |
| 1582 |
|
| 1583 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 1584 |
return; |
| 1585 |
|
| 1586 |
if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ()) |
| 1587 |
{ |
| 1588 |
_gdk_window_move_resize_child (window, window->x, window->y, width, height); |
| 1589 |
} |
| 1590 |
else |
| 1591 |
{ |
| 1592 |
RECT outer_rect; |
| 1593 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1594 |
|
| 1595 |
get_outer_rect (window, width, height, &outer_rect); |
| 1596 |
|
| 1597 |
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,0,0,%ld,%ld," |
| 1598 |
"NOACTIVATE|NOMOVE|NOZORDER)\n", |
| 1599 |
GDK_WINDOW_HWND (window), |
| 1600 |
outer_rect.right - outer_rect.left, |
| 1601 |
outer_rect.bottom - outer_rect.top)); |
| 1602 |
|
| 1603 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1604 |
SWP_NOZORDER_SPECIFIED, |
| 1605 |
0, 0, |
| 1606 |
outer_rect.right - outer_rect.left, |
| 1607 |
outer_rect.bottom - outer_rect.top, |
| 1608 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER)); |
| 1609 |
window->resize_count += 1; |
| 1610 |
} |
| 1611 |
} |
| 1612 |
|
| 1613 |
static void |
| 1614 |
gdk_win32_window_move_resize_internal (GdkWindow *window, |
| 1615 |
gint x, |
| 1616 |
gint y, |
| 1617 |
gint width, |
| 1618 |
gint height) |
| 1619 |
{ |
| 1620 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1621 |
|
| 1622 |
if (GDK_WINDOW_DESTROYED (window)) |
| 1623 |
return; |
| 1624 |
|
| 1625 |
if (width < 1) |
| 1626 |
width = 1; |
| 1627 |
if (height < 1) |
| 1628 |
height = 1; |
| 1629 |
|
| 1630 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 1631 |
return; |
| 1632 |
|
| 1633 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_move_resize: %p: %dx%d@%+d%+d\n", |
| 1634 |
GDK_WINDOW_HWND (window), |
| 1635 |
width, height, x, y)); |
| 1636 |
|
| 1637 |
if (GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) != GetDesktopWindow ()) |
| 1638 |
{ |
| 1639 |
_gdk_window_move_resize_child (window, x, y, width, height); |
| 1640 |
} |
| 1641 |
else |
| 1642 |
{ |
| 1643 |
RECT outer_rect; |
| 1644 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1645 |
|
| 1646 |
get_outer_rect (window, width, height, &outer_rect); |
| 1647 |
|
| 1648 |
adjust_for_gravity_hints (window, &outer_rect, &x, &y); |
| 1649 |
|
| 1650 |
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%ld,%ld," |
| 1651 |
"NOACTIVATE|NOZORDER)\n", |
| 1652 |
GDK_WINDOW_HWND (window), |
| 1653 |
x * impl->window_scale - _gdk_offset_x, |
| 1654 |
y * impl->window_scale - _gdk_offset_y, |
| 1655 |
outer_rect.right - outer_rect.left, |
| 1656 |
outer_rect.bottom - outer_rect.top)); |
| 1657 |
|
| 1658 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 1659 |
SWP_NOZORDER_SPECIFIED, |
| 1660 |
x * impl->window_scale - _gdk_offset_x, |
| 1661 |
y * impl->window_scale - _gdk_offset_y, |
| 1662 |
outer_rect.right - outer_rect.left, |
| 1663 |
outer_rect.bottom - outer_rect.top, |
| 1664 |
SWP_NOACTIVATE | SWP_NOZORDER)); |
| 1665 |
} |
| 1666 |
} |
| 1667 |
|
| 1668 |
static void |
| 1669 |
gdk_win32_window_move_resize (GdkWindow *window, |
| 1670 |
gboolean with_move, |
| 1671 |
gint x, |
| 1672 |
gint y, |
| 1673 |
gint width, |
| 1674 |
gint height) |
| 1675 |
{ |
| 1676 |
GdkWindowImplWin32 *window_impl; |
| 1677 |
|
| 1678 |
window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1679 |
window_impl->inhibit_configure = TRUE; |
| 1680 |
|
| 1681 |
/* We ignore changes to the window being moved or resized by the |
| 1682 |
user, as we don't want to fight the user */ |
| 1683 |
if (GDK_WINDOW_HWND (window) == _modal_move_resize_window) |
| 1684 |
goto out; |
| 1685 |
|
| 1686 |
if (with_move && (width < 0 && height < 0)) |
| 1687 |
{ |
| 1688 |
gdk_win32_window_move (window, x, y); |
| 1689 |
} |
| 1690 |
else |
| 1691 |
{ |
| 1692 |
gdk_win32_window_invalidate_egl_framebuffer (window); |
| 1693 |
if (with_move) |
| 1694 |
{ |
| 1695 |
gdk_win32_window_move_resize_internal (window, x, y, width, height); |
| 1696 |
} |
| 1697 |
else |
| 1698 |
{ |
| 1699 |
gdk_win32_window_resize (window, width, height); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
|
| 1703 |
out: |
| 1704 |
window_impl->inhibit_configure = FALSE; |
| 1705 |
|
| 1706 |
if (WINDOW_IS_TOPLEVEL (window)) |
| 1707 |
_gdk_win32_emit_configure_event (window); |
| 1708 |
} |
| 1709 |
|
| 1710 |
static gboolean |
| 1711 |
gdk_win32_window_reparent (GdkWindow *window, |
| 1712 |
GdkWindow *new_parent, |
| 1713 |
gint x, |
| 1714 |
gint y) |
| 1715 |
{ |
| 1716 |
GdkScreen *screen; |
| 1717 |
GdkWindowImplWin32 *impl; |
| 1718 |
gboolean new_parent_is_root; |
| 1719 |
gboolean was_toplevel; |
| 1720 |
LONG style; |
| 1721 |
|
| 1722 |
screen = gdk_window_get_screen (window); |
| 1723 |
|
| 1724 |
if (!new_parent) |
| 1725 |
{ |
| 1726 |
new_parent = gdk_screen_get_root_window (screen); |
| 1727 |
new_parent_is_root = TRUE; |
| 1728 |
} |
| 1729 |
else |
| 1730 |
new_parent_is_root = (gdk_screen_get_root_window (screen) == new_parent); |
| 1731 |
|
| 1732 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1733 |
|
| 1734 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_reparent: %p: %p\n", |
| 1735 |
GDK_WINDOW_HWND (window), |
| 1736 |
GDK_WINDOW_HWND (new_parent))); |
| 1737 |
|
| 1738 |
style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE); |
| 1739 |
|
| 1740 |
was_toplevel = GetAncestor (GDK_WINDOW_HWND (window), GA_PARENT) == GetDesktopWindow (); |
| 1741 |
if (was_toplevel && !new_parent_is_root) |
| 1742 |
{ |
| 1743 |
/* Reparenting from top-level (child of desktop). Clear out |
| 1744 |
* decorations. |
| 1745 |
*/ |
| 1746 |
style &= ~(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); |
| 1747 |
style |= WS_CHILD; |
| 1748 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style); |
| 1749 |
} |
| 1750 |
else if (new_parent_is_root) |
| 1751 |
{ |
| 1752 |
/* Reparenting to top-level. Add decorations. */ |
| 1753 |
style &= ~(WS_CHILD); |
| 1754 |
style |= WS_OVERLAPPEDWINDOW; |
| 1755 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, style); |
| 1756 |
} |
| 1757 |
|
| 1758 |
API_CALL (SetParent, (GDK_WINDOW_HWND (window), |
| 1759 |
GDK_WINDOW_HWND (new_parent))); |
| 1760 |
|
| 1761 |
/* From here on, we treat parents of type GDK_WINDOW_FOREIGN like |
| 1762 |
* the root window |
| 1763 |
*/ |
| 1764 |
if (GDK_WINDOW_TYPE (new_parent) == GDK_WINDOW_FOREIGN) |
| 1765 |
new_parent = gdk_screen_get_root_window (screen); |
| 1766 |
|
| 1767 |
window->parent = new_parent; |
| 1768 |
|
| 1769 |
/* Switch the window type as appropriate */ |
| 1770 |
|
| 1771 |
switch (GDK_WINDOW_TYPE (new_parent)) |
| 1772 |
{ |
| 1773 |
case GDK_WINDOW_ROOT: |
| 1774 |
if (impl->toplevel_window_type != -1) |
| 1775 |
GDK_WINDOW_TYPE (window) = impl->toplevel_window_type; |
| 1776 |
else if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD) |
| 1777 |
GDK_WINDOW_TYPE (window) = GDK_WINDOW_TOPLEVEL; |
| 1778 |
break; |
| 1779 |
|
| 1780 |
case GDK_WINDOW_TOPLEVEL: |
| 1781 |
case GDK_WINDOW_CHILD: |
| 1782 |
case GDK_WINDOW_TEMP: |
| 1783 |
if (WINDOW_IS_TOPLEVEL (window)) |
| 1784 |
{ |
| 1785 |
/* Save the original window type so we can restore it if the |
| 1786 |
* window is reparented back to be a toplevel. |
| 1787 |
*/ |
| 1788 |
impl->toplevel_window_type = GDK_WINDOW_TYPE (window); |
| 1789 |
GDK_WINDOW_TYPE (window) = GDK_WINDOW_CHILD; |
| 1790 |
} |
| 1791 |
} |
| 1792 |
|
| 1793 |
/* Move window into desired position while keeping the same client area */ |
| 1794 |
gdk_win32_window_move_resize (window, TRUE, x, y, window->width, window->height); |
| 1795 |
|
| 1796 |
return FALSE; |
| 1797 |
} |
| 1798 |
|
| 1799 |
static void |
| 1800 |
gdk_win32_window_raise (GdkWindow *window) |
| 1801 |
{ |
| 1802 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 1803 |
{ |
| 1804 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_raise: %p\n", |
| 1805 |
GDK_WINDOW_HWND (window))); |
| 1806 |
|
| 1807 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TEMP) |
| 1808 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOPMOST, |
| 1809 |
0, 0, 0, 0, |
| 1810 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER)); |
| 1811 |
else if (window->accept_focus) |
| 1812 |
/* Do not wrap this in an API_CALL macro as SetForegroundWindow might |
| 1813 |
* fail when for example dragging a window belonging to a different |
| 1814 |
* application at the time of a gtk_window_present() call due to focus |
| 1815 |
* stealing prevention. */ |
| 1816 |
SetForegroundWindow (GDK_WINDOW_HWND (window)); |
| 1817 |
else |
| 1818 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOP, |
| 1819 |
0, 0, 0, 0, |
| 1820 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE)); |
| 1821 |
} |
| 1822 |
} |
| 1823 |
|
| 1824 |
static void |
| 1825 |
gdk_win32_window_lower (GdkWindow *window) |
| 1826 |
{ |
| 1827 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 1828 |
{ |
| 1829 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_lower: %p\n" |
| 1830 |
"... SetWindowPos(%p,HWND_BOTTOM,0,0,0,0," |
| 1831 |
"NOACTIVATE|NOMOVE|NOSIZE)\n", |
| 1832 |
GDK_WINDOW_HWND (window), |
| 1833 |
GDK_WINDOW_HWND (window))); |
| 1834 |
|
| 1835 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_BOTTOM, |
| 1836 |
0, 0, 0, 0, |
| 1837 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE)); |
| 1838 |
} |
| 1839 |
} |
| 1840 |
|
| 1841 |
static void |
| 1842 |
gdk_win32_window_set_urgency_hint (GdkWindow *window, |
| 1843 |
gboolean urgent) |
| 1844 |
{ |
| 1845 |
FLASHWINFO flashwinfo; |
| 1846 |
typedef BOOL (WINAPI *PFN_FlashWindowEx) (FLASHWINFO*); |
| 1847 |
PFN_FlashWindowEx flashWindowEx = NULL; |
| 1848 |
|
| 1849 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1850 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 1851 |
|
| 1852 |
if (GDK_WINDOW_DESTROYED (window)) |
| 1853 |
return; |
| 1854 |
|
| 1855 |
flashWindowEx = (PFN_FlashWindowEx) GetProcAddress (GetModuleHandle ("user32.dll"), "FlashWindowEx"); |
| 1856 |
|
| 1857 |
if (flashWindowEx) |
| 1858 |
{ |
| 1859 |
flashwinfo.cbSize = sizeof (flashwinfo); |
| 1860 |
flashwinfo.hwnd = GDK_WINDOW_HWND (window); |
| 1861 |
if (urgent) |
| 1862 |
flashwinfo.dwFlags = FLASHW_ALL | FLASHW_TIMER; |
| 1863 |
else |
| 1864 |
flashwinfo.dwFlags = FLASHW_STOP; |
| 1865 |
flashwinfo.uCount = 0; |
| 1866 |
flashwinfo.dwTimeout = 0; |
| 1867 |
|
| 1868 |
flashWindowEx (&flashwinfo); |
| 1869 |
} |
| 1870 |
else |
| 1871 |
{ |
| 1872 |
FlashWindow (GDK_WINDOW_HWND (window), urgent); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
|
| 1876 |
static gboolean |
| 1877 |
get_effective_window_decorations (GdkWindow *window, |
| 1878 |
GdkWMDecoration *decoration) |
| 1879 |
{ |
| 1880 |
GdkWindowImplWin32 *impl; |
| 1881 |
|
| 1882 |
impl = (GdkWindowImplWin32 *)window->impl; |
| 1883 |
|
| 1884 |
if (gdk_window_get_decorations (window, decoration)) |
| 1885 |
return TRUE; |
| 1886 |
|
| 1887 |
if (window->window_type != GDK_WINDOW_TOPLEVEL) |
| 1888 |
{ |
| 1889 |
return FALSE; |
| 1890 |
} |
| 1891 |
|
| 1892 |
if ((impl->hint_flags & GDK_HINT_MIN_SIZE) && |
| 1893 |
(impl->hint_flags & GDK_HINT_MAX_SIZE) && |
| 1894 |
impl->hints.min_width == impl->hints.max_width && |
| 1895 |
impl->hints.min_height == impl->hints.max_height) |
| 1896 |
{ |
| 1897 |
*decoration = GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MAXIMIZE; |
| 1898 |
|
| 1899 |
if (impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG || |
| 1900 |
impl->type_hint == GDK_WINDOW_TYPE_HINT_MENU || |
| 1901 |
impl->type_hint == GDK_WINDOW_TYPE_HINT_TOOLBAR) |
| 1902 |
{ |
| 1903 |
*decoration |= GDK_DECOR_MINIMIZE; |
| 1904 |
} |
| 1905 |
else if (impl->type_hint == GDK_WINDOW_TYPE_HINT_SPLASHSCREEN) |
| 1906 |
{ |
| 1907 |
*decoration |= GDK_DECOR_MENU | GDK_DECOR_MINIMIZE; |
| 1908 |
} |
| 1909 |
|
| 1910 |
return TRUE; |
| 1911 |
} |
| 1912 |
else if (impl->hint_flags & GDK_HINT_MAX_SIZE) |
| 1913 |
{ |
| 1914 |
*decoration = GDK_DECOR_ALL | GDK_DECOR_MAXIMIZE; |
| 1915 |
if (impl->type_hint == GDK_WINDOW_TYPE_HINT_DIALOG || |
| 1916 |
impl->type_hint == GDK_WINDOW_TYPE_HINT_MENU || |
| 1917 |
impl->type_hint == GDK_WINDOW_TYPE_HINT_TOOLBAR) |
| 1918 |
{ |
| 1919 |
*decoration |= GDK_DECOR_MINIMIZE; |
| 1920 |
} |
| 1921 |
|
| 1922 |
return TRUE; |
| 1923 |
} |
| 1924 |
else |
| 1925 |
{ |
| 1926 |
switch (impl->type_hint) |
| 1927 |
{ |
| 1928 |
case GDK_WINDOW_TYPE_HINT_DIALOG: |
| 1929 |
*decoration = (GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE); |
| 1930 |
return TRUE; |
| 1931 |
|
| 1932 |
case GDK_WINDOW_TYPE_HINT_MENU: |
| 1933 |
*decoration = (GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE); |
| 1934 |
return TRUE; |
| 1935 |
|
| 1936 |
case GDK_WINDOW_TYPE_HINT_TOOLBAR: |
| 1937 |
case GDK_WINDOW_TYPE_HINT_UTILITY: |
| 1938 |
gdk_window_set_skip_taskbar_hint (window, TRUE); |
| 1939 |
gdk_window_set_skip_pager_hint (window, TRUE); |
| 1940 |
*decoration = (GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE); |
| 1941 |
return TRUE; |
| 1942 |
|
| 1943 |
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN: |
| 1944 |
*decoration = (GDK_DECOR_ALL | GDK_DECOR_RESIZEH | GDK_DECOR_MENU | |
| 1945 |
GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE); |
| 1946 |
return TRUE; |
| 1947 |
|
| 1948 |
case GDK_WINDOW_TYPE_HINT_DOCK: |
| 1949 |
return FALSE; |
| 1950 |
|
| 1951 |
case GDK_WINDOW_TYPE_HINT_DESKTOP: |
| 1952 |
return FALSE; |
| 1953 |
|
| 1954 |
default: |
| 1955 |
/* Fall thru */ |
| 1956 |
case GDK_WINDOW_TYPE_HINT_NORMAL: |
| 1957 |
*decoration = GDK_DECOR_ALL; |
| 1958 |
return TRUE; |
| 1959 |
} |
| 1960 |
} |
| 1961 |
|
| 1962 |
return FALSE; |
| 1963 |
} |
| 1964 |
|
| 1965 |
static void |
| 1966 |
gdk_win32_window_set_geometry_hints (GdkWindow *window, |
| 1967 |
const GdkGeometry *geometry, |
| 1968 |
GdkWindowHints geom_mask) |
| 1969 |
{ |
| 1970 |
GdkWindowImplWin32 *impl; |
| 1971 |
FullscreenInfo *fi; |
| 1972 |
|
| 1973 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 1974 |
|
| 1975 |
if (GDK_WINDOW_DESTROYED (window)) |
| 1976 |
return; |
| 1977 |
|
| 1978 |
GDK_NOTE (MISC, g_print ("gdk_window_set_geometry_hints: %p\n", |
| 1979 |
GDK_WINDOW_HWND (window))); |
| 1980 |
|
| 1981 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1982 |
|
| 1983 |
fi = g_object_get_data (G_OBJECT (window), "fullscreen-info"); |
| 1984 |
if (fi) |
| 1985 |
fi->hint_flags = geom_mask; |
| 1986 |
else |
| 1987 |
impl->hint_flags = geom_mask; |
| 1988 |
impl->hints = *geometry; |
| 1989 |
|
| 1990 |
if (geom_mask & GDK_HINT_POS) |
| 1991 |
{ |
| 1992 |
/* even the X11 mplementation doesn't care */ |
| 1993 |
} |
| 1994 |
|
| 1995 |
if (geom_mask & GDK_HINT_MIN_SIZE) |
| 1996 |
{ |
| 1997 |
GDK_NOTE (MISC, g_print ("... MIN_SIZE: %dx%d\n", |
| 1998 |
geometry->min_width, geometry->min_height)); |
| 1999 |
} |
| 2000 |
|
| 2001 |
if (geom_mask & GDK_HINT_MAX_SIZE) |
| 2002 |
{ |
| 2003 |
GDK_NOTE (MISC, g_print ("... MAX_SIZE: %dx%d\n", |
| 2004 |
geometry->max_width, geometry->max_height)); |
| 2005 |
} |
| 2006 |
|
| 2007 |
if (geom_mask & GDK_HINT_BASE_SIZE) |
| 2008 |
{ |
| 2009 |
GDK_NOTE (MISC, g_print ("... BASE_SIZE: %dx%d\n", |
| 2010 |
geometry->base_width, geometry->base_height)); |
| 2011 |
} |
| 2012 |
|
| 2013 |
if (geom_mask & GDK_HINT_RESIZE_INC) |
| 2014 |
{ |
| 2015 |
GDK_NOTE (MISC, g_print ("... RESIZE_INC: (%d,%d)\n", |
| 2016 |
geometry->width_inc, geometry->height_inc)); |
| 2017 |
} |
| 2018 |
|
| 2019 |
if (geom_mask & GDK_HINT_ASPECT) |
| 2020 |
{ |
| 2021 |
GDK_NOTE (MISC, g_print ("... ASPECT: %g--%g\n", |
| 2022 |
geometry->min_aspect, geometry->max_aspect)); |
| 2023 |
} |
| 2024 |
|
| 2025 |
if (geom_mask & GDK_HINT_WIN_GRAVITY) |
| 2026 |
{ |
| 2027 |
GDK_NOTE (MISC, g_print ("... GRAVITY: %d\n", geometry->win_gravity)); |
| 2028 |
} |
| 2029 |
|
| 2030 |
_gdk_win32_window_update_style_bits (window); |
| 2031 |
} |
| 2032 |
|
| 2033 |
static void |
| 2034 |
gdk_win32_window_set_title (GdkWindow *window, |
| 2035 |
const gchar *title) |
| 2036 |
{ |
| 2037 |
wchar_t *wtitle; |
| 2038 |
|
| 2039 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2040 |
g_return_if_fail (title != NULL); |
| 2041 |
|
| 2042 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2043 |
return; |
| 2044 |
|
| 2045 |
/* Empty window titles not allowed, so set it to just a period. */ |
| 2046 |
if (!title[0]) |
| 2047 |
title = "."; |
| 2048 |
|
| 2049 |
GDK_NOTE (MISC, g_print ("gdk_window_set_title: %p: %s\n", |
| 2050 |
GDK_WINDOW_HWND (window), title)); |
| 2051 |
|
| 2052 |
GDK_NOTE (MISC_OR_EVENTS, title = g_strdup_printf ("%p %s", GDK_WINDOW_HWND (window), title)); |
| 2053 |
|
| 2054 |
wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL); |
| 2055 |
API_CALL (SetWindowTextW, (GDK_WINDOW_HWND (window), wtitle)); |
| 2056 |
g_free (wtitle); |
| 2057 |
|
| 2058 |
GDK_NOTE (MISC_OR_EVENTS, g_free ((char *) title)); |
| 2059 |
} |
| 2060 |
|
| 2061 |
static void |
| 2062 |
gdk_win32_window_set_role (GdkWindow *window, |
| 2063 |
const gchar *role) |
| 2064 |
{ |
| 2065 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2066 |
|
| 2067 |
GDK_NOTE (MISC, g_print ("gdk_window_set_role: %p: %s\n", |
| 2068 |
GDK_WINDOW_HWND (window), |
| 2069 |
(role ? role : "NULL"))); |
| 2070 |
/* XXX */ |
| 2071 |
} |
| 2072 |
|
| 2073 |
static void |
| 2074 |
gdk_win32_window_set_transient_for (GdkWindow *window, |
| 2075 |
GdkWindow *parent) |
| 2076 |
{ |
| 2077 |
HWND window_id, parent_id; |
| 2078 |
LONG_PTR old_ptr; |
| 2079 |
DWORD w32_error; |
| 2080 |
GdkWindowImplWin32 *window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2081 |
GdkWindowImplWin32 *parent_impl = NULL; |
| 2082 |
GSList *item; |
| 2083 |
|
| 2084 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2085 |
|
| 2086 |
window_id = GDK_WINDOW_HWND (window); |
| 2087 |
parent_id = parent != NULL ? GDK_WINDOW_HWND (parent) : NULL; |
| 2088 |
|
| 2089 |
GDK_NOTE (MISC, g_print ("gdk_window_set_transient_for: %p: %p\n", window_id, parent_id)); |
| 2090 |
|
| 2091 |
if (GDK_WINDOW_DESTROYED (window) || (parent && GDK_WINDOW_DESTROYED (parent))) |
| 2092 |
{ |
| 2093 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2094 |
GDK_NOTE (MISC, g_print ("... destroyed!\n")); |
| 2095 |
else |
| 2096 |
GDK_NOTE (MISC, g_print ("... owner destroyed!\n")); |
| 2097 |
|
| 2098 |
return; |
| 2099 |
} |
| 2100 |
|
| 2101 |
if (window->window_type == GDK_WINDOW_CHILD) |
| 2102 |
{ |
| 2103 |
GDK_NOTE (MISC, g_print ("... a child window!\n")); |
| 2104 |
return; |
| 2105 |
} |
| 2106 |
|
| 2107 |
if (window_impl->transient_owner == parent) |
| 2108 |
return; |
| 2109 |
|
| 2110 |
if (GDK_IS_WINDOW (window_impl->transient_owner)) |
| 2111 |
{ |
| 2112 |
GdkWindowImplWin32 *trans_impl = GDK_WINDOW_IMPL_WIN32 (window_impl->transient_owner->impl); |
| 2113 |
item = g_slist_find (trans_impl->transient_children, window); |
| 2114 |
item->data = NULL; |
| 2115 |
trans_impl->transient_children = g_slist_delete_link (trans_impl->transient_children, item); |
| 2116 |
trans_impl->num_transients--; |
| 2117 |
|
| 2118 |
if (!trans_impl->num_transients) |
| 2119 |
{ |
| 2120 |
trans_impl->transient_children = NULL; |
| 2121 |
} |
| 2122 |
|
| 2123 |
g_object_unref (G_OBJECT (window_impl->transient_owner)); |
| 2124 |
g_object_unref (G_OBJECT (window)); |
| 2125 |
|
| 2126 |
window_impl->transient_owner = NULL; |
| 2127 |
} |
| 2128 |
|
| 2129 |
if (parent) |
| 2130 |
{ |
| 2131 |
parent_impl = GDK_WINDOW_IMPL_WIN32 (parent->impl); |
| 2132 |
|
| 2133 |
parent_impl->transient_children = g_slist_append (parent_impl->transient_children, window); |
| 2134 |
g_object_ref (G_OBJECT (window)); |
| 2135 |
parent_impl->num_transients++; |
| 2136 |
window_impl->transient_owner = parent; |
| 2137 |
g_object_ref (G_OBJECT (parent)); |
| 2138 |
} |
| 2139 |
|
| 2140 |
SetLastError (0); |
| 2141 |
old_ptr = GetWindowLongPtr (window_id, GWLP_HWNDPARENT); |
| 2142 |
w32_error = GetLastError (); |
| 2143 |
|
| 2144 |
/* Don't re-set GWLP_HWNDPARENT to the same value */ |
| 2145 |
if ((HWND) old_ptr == parent_id && w32_error == NO_ERROR) |
| 2146 |
return; |
| 2147 |
|
| 2148 |
/* Don't return if it failed, try SetWindowLongPtr() anyway */ |
| 2149 |
if (old_ptr == 0 && w32_error != NO_ERROR) |
| 2150 |
WIN32_API_FAILED ("GetWindowLongPtr"); |
| 2151 |
|
| 2152 |
/* This changes the *owner* of the window, despite the misleading |
| 2153 |
* name. (Owner and parent are unrelated concepts.) At least that's |
| 2154 |
* what people who seem to know what they talk about say on |
| 2155 |
* USENET. Search on Google. |
| 2156 |
*/ |
| 2157 |
SetLastError (0); |
| 2158 |
old_ptr = SetWindowLongPtr (window_id, GWLP_HWNDPARENT, (LONG_PTR) parent_id); |
| 2159 |
w32_error = GetLastError (); |
| 2160 |
|
| 2161 |
if (old_ptr == 0 && w32_error != NO_ERROR) |
| 2162 |
WIN32_API_FAILED ("SetWindowLongPtr"); |
| 2163 |
} |
| 2164 |
|
| 2165 |
void |
| 2166 |
_gdk_push_modal_window (GdkWindow *window) |
| 2167 |
{ |
| 2168 |
modal_window_stack = g_slist_prepend (modal_window_stack, |
| 2169 |
window); |
| 2170 |
} |
| 2171 |
|
| 2172 |
void |
| 2173 |
_gdk_remove_modal_window (GdkWindow *window) |
| 2174 |
{ |
| 2175 |
GSList *tmp; |
| 2176 |
|
| 2177 |
g_return_if_fail (window != NULL); |
| 2178 |
|
| 2179 |
/* It's possible to be NULL here if someone sets the modal hint of the window |
| 2180 |
* to FALSE before a modal window stack has ever been created. */ |
| 2181 |
if (modal_window_stack == NULL) |
| 2182 |
return; |
| 2183 |
|
| 2184 |
/* Find the requested window in the stack and remove it. Yeah, I realize this |
| 2185 |
* means we're not a 'real stack', strictly speaking. Sue me. :) */ |
| 2186 |
tmp = g_slist_find (modal_window_stack, window); |
| 2187 |
if (tmp != NULL) |
| 2188 |
{ |
| 2189 |
modal_window_stack = g_slist_delete_link (modal_window_stack, tmp); |
| 2190 |
} |
| 2191 |
} |
| 2192 |
|
| 2193 |
gboolean |
| 2194 |
_gdk_modal_blocked (GdkWindow *window) |
| 2195 |
{ |
| 2196 |
GSList *l; |
| 2197 |
gboolean found_any = FALSE; |
| 2198 |
|
| 2199 |
for (l = modal_window_stack; l != NULL; l = l->next) |
| 2200 |
{ |
| 2201 |
GdkWindow *modal = l->data; |
| 2202 |
|
| 2203 |
if (modal == window) |
| 2204 |
return FALSE; |
| 2205 |
|
| 2206 |
if (GDK_WINDOW_IS_MAPPED (modal)) |
| 2207 |
found_any = TRUE; |
| 2208 |
} |
| 2209 |
|
| 2210 |
return found_any; |
| 2211 |
} |
| 2212 |
|
| 2213 |
GdkWindow * |
| 2214 |
_gdk_modal_current (void) |
| 2215 |
{ |
| 2216 |
GSList *l; |
| 2217 |
|
| 2218 |
for (l = modal_window_stack; l != NULL; l = l->next) |
| 2219 |
{ |
| 2220 |
GdkWindow *modal = l->data; |
| 2221 |
|
| 2222 |
if (GDK_WINDOW_IS_MAPPED (modal)) |
| 2223 |
return modal; |
| 2224 |
} |
| 2225 |
|
| 2226 |
return NULL; |
| 2227 |
} |
| 2228 |
|
| 2229 |
static void |
| 2230 |
gdk_win32_window_set_background (GdkWindow *window, |
| 2231 |
cairo_pattern_t *pattern) |
| 2232 |
{ |
| 2233 |
} |
| 2234 |
|
| 2235 |
static void |
| 2236 |
gdk_win32_window_set_device_cursor (GdkWindow *window, |
| 2237 |
GdkDevice *device, |
| 2238 |
GdkCursor *cursor) |
| 2239 |
{ |
| 2240 |
GdkWindowImplWin32 *impl; |
| 2241 |
GdkCursor *previous_cursor; |
| 2242 |
|
| 2243 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2244 |
|
| 2245 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2246 |
return; |
| 2247 |
|
| 2248 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_set_cursor: %p: %p\n", |
| 2249 |
GDK_WINDOW_HWND (window), |
| 2250 |
cursor)); |
| 2251 |
|
| 2252 |
/* First get the old cursor, if any (we wait to free the old one |
| 2253 |
* since it may be the current cursor set in the Win32 API right |
| 2254 |
* now). |
| 2255 |
*/ |
| 2256 |
previous_cursor = impl->cursor; |
| 2257 |
|
| 2258 |
if (cursor) |
| 2259 |
impl->cursor = g_object_ref (cursor); |
| 2260 |
else |
| 2261 |
/* Use default cursor otherwise. Don't just set NULL cursor, |
| 2262 |
* because that will just hide the cursor, which is not |
| 2263 |
* what the caller probably wanted. |
| 2264 |
*/ |
| 2265 |
impl->cursor = _gdk_win32_display_get_cursor_for_type (gdk_device_get_display (device), |
| 2266 |
GDK_LEFT_PTR); |
| 2267 |
|
| 2268 |
GDK_DEVICE_GET_CLASS (device)->set_window_cursor (device, window, impl->cursor); |
| 2269 |
|
| 2270 |
/* Destroy the previous cursor */ |
| 2271 |
if (previous_cursor != NULL) |
| 2272 |
g_object_unref (previous_cursor); |
| 2273 |
} |
| 2274 |
|
| 2275 |
static void |
| 2276 |
gdk_win32_window_get_geometry (GdkWindow *window, |
| 2277 |
gint *x, |
| 2278 |
gint *y, |
| 2279 |
gint *width, |
| 2280 |
gint *height) |
| 2281 |
{ |
| 2282 |
GdkScreen *screen; |
| 2283 |
gboolean window_is_root; |
| 2284 |
|
| 2285 |
screen = gdk_window_get_screen (window); |
| 2286 |
|
| 2287 |
if (!window) |
| 2288 |
{ |
| 2289 |
window = gdk_screen_get_root_window (screen); |
| 2290 |
window_is_root = TRUE; |
| 2291 |
} |
| 2292 |
else |
| 2293 |
window_is_root = (gdk_screen_get_root_window (screen) == window); |
| 2294 |
|
| 2295 |
if (!GDK_WINDOW_DESTROYED (window)) |
| 2296 |
{ |
| 2297 |
RECT rect; |
| 2298 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2299 |
|
| 2300 |
API_CALL (GetClientRect, (GDK_WINDOW_HWND (window), &rect)); |
| 2301 |
|
| 2302 |
if (!window_is_root) |
| 2303 |
{ |
| 2304 |
POINT pt; |
| 2305 |
GdkWindow *parent = gdk_window_get_parent (window); |
| 2306 |
|
| 2307 |
pt.x = rect.left; |
| 2308 |
pt.y = rect.top; |
| 2309 |
ClientToScreen (GDK_WINDOW_HWND (window), &pt); |
| 2310 |
ScreenToClient (GDK_WINDOW_HWND (parent), &pt); |
| 2311 |
rect.left = pt.x; |
| 2312 |
rect.top = pt.y; |
| 2313 |
|
| 2314 |
pt.x = rect.right; |
| 2315 |
pt.y = rect.bottom; |
| 2316 |
ClientToScreen (GDK_WINDOW_HWND (window), &pt); |
| 2317 |
ScreenToClient (GDK_WINDOW_HWND (parent), &pt); |
| 2318 |
rect.right = pt.x; |
| 2319 |
rect.bottom = pt.y; |
| 2320 |
|
| 2321 |
if (gdk_screen_get_root_window (screen) == parent) |
| 2322 |
{ |
| 2323 |
rect.left += _gdk_offset_x; |
| 2324 |
rect.top += _gdk_offset_y; |
| 2325 |
rect.right += _gdk_offset_x; |
| 2326 |
rect.bottom += _gdk_offset_y; |
| 2327 |
} |
| 2328 |
} |
| 2329 |
|
| 2330 |
if (x) |
| 2331 |
*x = rect.left / impl->window_scale; |
| 2332 |
if (y) |
| 2333 |
*y = rect.top / impl->window_scale; |
| 2334 |
if (width) |
| 2335 |
*width = (rect.right - rect.left) / impl->window_scale; |
| 2336 |
if (height) |
| 2337 |
*height = (rect.bottom - rect.top) / impl->window_scale; |
| 2338 |
|
| 2339 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_get_geometry: %p: %ldx%ldx%d@%+ld%+ld\n", |
| 2340 |
GDK_WINDOW_HWND (window), |
| 2341 |
(rect.right - rect.left) / impl->window_scale, |
| 2342 |
(rect.bottom - rect.top) / impl->window_scale, |
| 2343 |
gdk_window_get_visual (window)->depth, |
| 2344 |
rect.left, rect.top)); |
| 2345 |
} |
| 2346 |
} |
| 2347 |
|
| 2348 |
static void |
| 2349 |
gdk_win32_window_get_root_coords (GdkWindow *window, |
| 2350 |
gint x, |
| 2351 |
gint y, |
| 2352 |
gint *root_x, |
| 2353 |
gint *root_y) |
| 2354 |
{ |
| 2355 |
gint tx; |
| 2356 |
gint ty; |
| 2357 |
POINT pt; |
| 2358 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2359 |
|
| 2360 |
pt.x = x * impl->window_scale; |
| 2361 |
pt.y = y * impl->window_scale; |
| 2362 |
ClientToScreen (GDK_WINDOW_HWND (window), &pt); |
| 2363 |
tx = pt.x; |
| 2364 |
ty = pt.y; |
| 2365 |
|
| 2366 |
if (root_x) |
| 2367 |
*root_x = (tx + _gdk_offset_x) / impl->window_scale; |
| 2368 |
if (root_y) |
| 2369 |
*root_y = (ty + _gdk_offset_y) / impl->window_scale; |
| 2370 |
|
| 2371 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_get_root_coords: %p: %+d%+d %+d%+d\n", |
| 2372 |
GDK_WINDOW_HWND (window), |
| 2373 |
x * impl->window_scale, |
| 2374 |
y * impl->window_scale, |
| 2375 |
(tx + _gdk_offset_x) / impl->window_scale, |
| 2376 |
(ty + _gdk_offset_y) / impl->window_scale)); |
| 2377 |
} |
| 2378 |
|
| 2379 |
static void |
| 2380 |
gdk_win32_window_restack_under (GdkWindow *window, |
| 2381 |
GList *native_siblings) |
| 2382 |
{ |
| 2383 |
// ### TODO |
| 2384 |
} |
| 2385 |
|
| 2386 |
static void |
| 2387 |
gdk_win32_window_restack_toplevel (GdkWindow *window, |
| 2388 |
GdkWindow *sibling, |
| 2389 |
gboolean above) |
| 2390 |
{ |
| 2391 |
// ### TODO |
| 2392 |
} |
| 2393 |
|
| 2394 |
static void |
| 2395 |
gdk_win32_window_get_frame_extents (GdkWindow *window, |
| 2396 |
GdkRectangle *rect) |
| 2397 |
{ |
| 2398 |
HWND hwnd; |
| 2399 |
RECT r; |
| 2400 |
GdkWindowImplWin32 *impl; |
| 2401 |
|
| 2402 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2403 |
g_return_if_fail (rect != NULL); |
| 2404 |
|
| 2405 |
rect->x = 0; |
| 2406 |
rect->y = 0; |
| 2407 |
rect->width = 1; |
| 2408 |
rect->height = 1; |
| 2409 |
|
| 2410 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2411 |
return; |
| 2412 |
|
| 2413 |
/* FIXME: window is documented to be a toplevel GdkWindow, so is it really |
| 2414 |
* necessary to walk its parent chain? |
| 2415 |
*/ |
| 2416 |
while (window->parent && window->parent->parent) |
| 2417 |
window = window->parent; |
| 2418 |
|
| 2419 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2420 |
hwnd = GDK_WINDOW_HWND (window); |
| 2421 |
API_CALL (GetWindowRect, (hwnd, &r)); |
| 2422 |
|
| 2423 |
/* Initialize GdkRectangle to unscaled coordinates */ |
| 2424 |
rect->x = r.left + _gdk_offset_x; |
| 2425 |
rect->y = r.top + _gdk_offset_y; |
| 2426 |
rect->width = (r.right - r.left); |
| 2427 |
rect->height = (r.bottom - r.top); |
| 2428 |
|
| 2429 |
/* Extend width and height to ensure that they cover the real size when de-scaled, |
| 2430 |
* and replace everything with scaled values |
| 2431 |
*/ |
| 2432 |
rect->width = (rect->width + rect->x % impl->window_scale + impl->window_scale - 1) / impl->window_scale; |
| 2433 |
rect->height = (rect->height + rect->y % impl->window_scale + impl->window_scale - 1) / impl->window_scale; |
| 2434 |
rect->x /= impl->window_scale; |
| 2435 |
rect->y /= impl->window_scale; |
| 2436 |
|
| 2437 |
GDK_NOTE (MISC, g_print ("gdk_window_get_frame_extents: %p: %ldx%ld@%+ld%+ld\n", |
| 2438 |
GDK_WINDOW_HWND (window), |
| 2439 |
rect->width, |
| 2440 |
rect->height, |
| 2441 |
rect->x, rect->y)); |
| 2442 |
} |
| 2443 |
|
| 2444 |
static gboolean |
| 2445 |
gdk_window_win32_get_device_state (GdkWindow *window, |
| 2446 |
GdkDevice *device, |
| 2447 |
gdouble *x, |
| 2448 |
gdouble *y, |
| 2449 |
GdkModifierType *mask) |
| 2450 |
{ |
| 2451 |
GdkWindow *child; |
| 2452 |
|
| 2453 |
g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), FALSE); |
| 2454 |
|
| 2455 |
GDK_DEVICE_GET_CLASS (device)->query_state (device, window, |
| 2456 |
NULL, &child, |
| 2457 |
NULL, NULL, |
| 2458 |
x, y, mask); |
| 2459 |
return (child != NULL); |
| 2460 |
} |
| 2461 |
|
| 2462 |
void |
| 2463 |
gdk_display_warp_device (GdkDisplay *display, |
| 2464 |
GdkDevice *device, |
| 2465 |
GdkScreen *screen, |
| 2466 |
gint x, |
| 2467 |
gint y) |
| 2468 |
{ |
| 2469 |
g_return_if_fail (display == gdk_display_get_default ()); |
| 2470 |
g_return_if_fail (screen == gdk_display_get_default_screen (display)); |
| 2471 |
g_return_if_fail (GDK_IS_DEVICE (device)); |
| 2472 |
g_return_if_fail (display == gdk_device_get_display (device)); |
| 2473 |
|
| 2474 |
GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y); |
| 2475 |
} |
| 2476 |
|
| 2477 |
static GdkEventMask |
| 2478 |
gdk_win32_window_get_events (GdkWindow *window) |
| 2479 |
{ |
| 2480 |
GdkWindowImplWin32 *impl; |
| 2481 |
|
| 2482 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2483 |
return 0; |
| 2484 |
|
| 2485 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2486 |
|
| 2487 |
return impl->native_event_mask; |
| 2488 |
} |
| 2489 |
|
| 2490 |
static void |
| 2491 |
gdk_win32_window_set_events (GdkWindow *window, |
| 2492 |
GdkEventMask event_mask) |
| 2493 |
{ |
| 2494 |
GdkWindowImplWin32 *impl; |
| 2495 |
|
| 2496 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2497 |
|
| 2498 |
/* gdk_window_new() always sets the GDK_STRUCTURE_MASK, so better |
| 2499 |
* set it here, too. Not that I know or remember why it is |
| 2500 |
* necessary, will have to test some day. |
| 2501 |
*/ |
| 2502 |
impl->native_event_mask = GDK_STRUCTURE_MASK | event_mask; |
| 2503 |
} |
| 2504 |
|
| 2505 |
static void |
| 2506 |
do_shape_combine_region (GdkWindow *window, |
| 2507 |
HRGN hrgn, |
| 2508 |
gint x, gint y) |
| 2509 |
{ |
| 2510 |
RECT rect; |
| 2511 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2512 |
|
| 2513 |
GetClientRect (GDK_WINDOW_HWND (window), &rect); |
| 2514 |
|
| 2515 |
_gdk_win32_adjust_client_rect (window, &rect); |
| 2516 |
|
| 2517 |
OffsetRgn (hrgn, -rect.left, -rect.top); |
| 2518 |
OffsetRgn (hrgn, x, y); |
| 2519 |
|
| 2520 |
/* If this is a top-level window, add the title bar to the region */ |
| 2521 |
if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_TOPLEVEL) |
| 2522 |
{ |
| 2523 |
HRGN tmp = CreateRectRgn (0, 0, rect.right - rect.left, -rect.top); |
| 2524 |
CombineRgn (hrgn, hrgn, tmp, RGN_OR); |
| 2525 |
DeleteObject (tmp); |
| 2526 |
} |
| 2527 |
|
| 2528 |
SetWindowRgn (GDK_WINDOW_HWND (window), hrgn, TRUE); |
| 2529 |
} |
| 2530 |
|
| 2531 |
static void |
| 2532 |
gdk_win32_window_set_override_redirect (GdkWindow *window, |
| 2533 |
gboolean override_redirect) |
| 2534 |
{ |
| 2535 |
GdkWindowImplWin32 *window_impl; |
| 2536 |
|
| 2537 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2538 |
|
| 2539 |
window_impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2540 |
|
| 2541 |
window_impl->override_redirect = !!override_redirect; |
| 2542 |
} |
| 2543 |
|
| 2544 |
static void |
| 2545 |
gdk_win32_window_set_accept_focus (GdkWindow *window, |
| 2546 |
gboolean accept_focus) |
| 2547 |
{ |
| 2548 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2549 |
|
| 2550 |
accept_focus = accept_focus != FALSE; |
| 2551 |
|
| 2552 |
if (window->accept_focus != accept_focus) |
| 2553 |
window->accept_focus = accept_focus; |
| 2554 |
} |
| 2555 |
|
| 2556 |
static void |
| 2557 |
gdk_win32_window_set_focus_on_map (GdkWindow *window, |
| 2558 |
gboolean focus_on_map) |
| 2559 |
{ |
| 2560 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2561 |
|
| 2562 |
focus_on_map = focus_on_map != FALSE; |
| 2563 |
|
| 2564 |
if (window->focus_on_map != focus_on_map) |
| 2565 |
window->focus_on_map = focus_on_map; |
| 2566 |
} |
| 2567 |
|
| 2568 |
static void |
| 2569 |
gdk_win32_window_set_icon_list (GdkWindow *window, |
| 2570 |
GList *pixbufs) |
| 2571 |
{ |
| 2572 |
GdkPixbuf *pixbuf, *big_pixbuf, *small_pixbuf; |
| 2573 |
gint big_diff, small_diff; |
| 2574 |
gint big_w, big_h, small_w, small_h; |
| 2575 |
gint w, h; |
| 2576 |
gint dw, dh, diff; |
| 2577 |
HICON small_hicon, big_hicon; |
| 2578 |
GdkWindowImplWin32 *impl; |
| 2579 |
|
| 2580 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2581 |
|
| 2582 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2583 |
return; |
| 2584 |
|
| 2585 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2586 |
|
| 2587 |
/* ideal sizes for small and large icons */ |
| 2588 |
big_w = GetSystemMetrics (SM_CXICON); |
| 2589 |
big_h = GetSystemMetrics (SM_CYICON); |
| 2590 |
small_w = GetSystemMetrics (SM_CXSMICON); |
| 2591 |
small_h = GetSystemMetrics (SM_CYSMICON); |
| 2592 |
|
| 2593 |
/* find closest sized icons in the list */ |
| 2594 |
big_pixbuf = NULL; |
| 2595 |
small_pixbuf = NULL; |
| 2596 |
big_diff = 0; |
| 2597 |
small_diff = 0; |
| 2598 |
while (pixbufs) |
| 2599 |
{ |
| 2600 |
pixbuf = (GdkPixbuf*) pixbufs->data; |
| 2601 |
w = gdk_pixbuf_get_width (pixbuf); |
| 2602 |
h = gdk_pixbuf_get_height (pixbuf); |
| 2603 |
|
| 2604 |
dw = ABS (w - big_w); |
| 2605 |
dh = ABS (h - big_h); |
| 2606 |
diff = dw*dw + dh*dh; |
| 2607 |
if (big_pixbuf == NULL || diff < big_diff) |
| 2608 |
{ |
| 2609 |
big_pixbuf = pixbuf; |
| 2610 |
big_diff = diff; |
| 2611 |
} |
| 2612 |
|
| 2613 |
dw = ABS (w - small_w); |
| 2614 |
dh = ABS (h - small_h); |
| 2615 |
diff = dw*dw + dh*dh; |
| 2616 |
if (small_pixbuf == NULL || diff < small_diff) |
| 2617 |
{ |
| 2618 |
small_pixbuf = pixbuf; |
| 2619 |
small_diff = diff; |
| 2620 |
} |
| 2621 |
|
| 2622 |
pixbufs = pixbufs->next; |
| 2623 |
} |
| 2624 |
|
| 2625 |
/* Create the icons */ |
| 2626 |
big_hicon = _gdk_win32_pixbuf_to_hicon (big_pixbuf); |
| 2627 |
small_hicon = _gdk_win32_pixbuf_to_hicon (small_pixbuf); |
| 2628 |
|
| 2629 |
/* Set the icons */ |
| 2630 |
SendMessageW (GDK_WINDOW_HWND (window), WM_SETICON, ICON_BIG, |
| 2631 |
(LPARAM)big_hicon); |
| 2632 |
SendMessageW (GDK_WINDOW_HWND (window), WM_SETICON, ICON_SMALL, |
| 2633 |
(LPARAM)small_hicon); |
| 2634 |
|
| 2635 |
/* Store the icons, destroying any previous icons */ |
| 2636 |
if (impl->hicon_big) |
| 2637 |
GDI_CALL (DestroyIcon, (impl->hicon_big)); |
| 2638 |
impl->hicon_big = big_hicon; |
| 2639 |
if (impl->hicon_small) |
| 2640 |
GDI_CALL (DestroyIcon, (impl->hicon_small)); |
| 2641 |
impl->hicon_small = small_hicon; |
| 2642 |
} |
| 2643 |
|
| 2644 |
static void |
| 2645 |
gdk_win32_window_set_icon_name (GdkWindow *window, |
| 2646 |
const gchar *name) |
| 2647 |
{ |
| 2648 |
/* In case I manage to confuse this again (or somebody else does): |
| 2649 |
* Please note that "icon name" here really *does* mean the name or |
| 2650 |
* title of an window minimized as an icon on the desktop, or in the |
| 2651 |
* taskbar. It has nothing to do with the freedesktop.org icon |
| 2652 |
* naming stuff. |
| 2653 |
*/ |
| 2654 |
|
| 2655 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2656 |
|
| 2657 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2658 |
return; |
| 2659 |
|
| 2660 |
#if 0 |
| 2661 |
/* This is not the correct thing to do. We should keep both the |
| 2662 |
* "normal" window title, and the icon name. When the window is |
| 2663 |
* minimized, call SetWindowText() with the icon name, and when the |
| 2664 |
* window is restored, with the normal window title. Also, the name |
| 2665 |
* is in UTF-8, so we should do the normal conversion to either wide |
| 2666 |
* chars or system codepage, and use either the W or A version of |
| 2667 |
* SetWindowText(), depending on Windows version. |
| 2668 |
*/ |
| 2669 |
API_CALL (SetWindowText, (GDK_WINDOW_HWND (window), name)); |
| 2670 |
#endif |
| 2671 |
} |
| 2672 |
|
| 2673 |
static GdkWindow * |
| 2674 |
gdk_win32_window_get_group (GdkWindow *window) |
| 2675 |
{ |
| 2676 |
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); |
| 2677 |
g_return_val_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD, NULL); |
| 2678 |
|
| 2679 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2680 |
return NULL; |
| 2681 |
|
| 2682 |
g_warning ("gdk_window_get_group not yet implemented"); |
| 2683 |
|
| 2684 |
return NULL; |
| 2685 |
} |
| 2686 |
|
| 2687 |
static void |
| 2688 |
gdk_win32_window_set_group (GdkWindow *window, |
| 2689 |
GdkWindow *leader) |
| 2690 |
{ |
| 2691 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2692 |
g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD); |
| 2693 |
g_return_if_fail (leader == NULL || GDK_IS_WINDOW (leader)); |
| 2694 |
|
| 2695 |
if (GDK_WINDOW_DESTROYED (window) || GDK_WINDOW_DESTROYED (leader)) |
| 2696 |
return; |
| 2697 |
|
| 2698 |
g_warning ("gdk_window_set_group not implemented"); |
| 2699 |
} |
| 2700 |
|
| 2701 |
static void |
| 2702 |
update_single_bit (LONG *style, |
| 2703 |
gboolean all, |
| 2704 |
int gdk_bit, |
| 2705 |
int style_bit) |
| 2706 |
{ |
| 2707 |
/* all controls the interpretation of gdk_bit -- if all is TRUE, |
| 2708 |
* gdk_bit indicates whether style_bit is off; if all is FALSE, gdk |
| 2709 |
* bit indicate whether style_bit is on |
| 2710 |
*/ |
| 2711 |
if ((!all && gdk_bit) || (all && !gdk_bit)) |
| 2712 |
*style |= style_bit; |
| 2713 |
else |
| 2714 |
*style &= ~style_bit; |
| 2715 |
} |
| 2716 |
|
| 2717 |
/* |
| 2718 |
* Returns TRUE if window has no decorations. |
| 2719 |
* Usually it means CSD windows, because GTK |
| 2720 |
* calls gdk_window_set_decorations (window, 0); |
| 2721 |
* This is used to decide whether a toplevel should |
| 2722 |
* be made layered, thus it |
| 2723 |
* only returns TRUE for toplevels (until GTK minimal |
| 2724 |
* system requirements are lifted to Windows 8 or newer, |
| 2725 |
* because only toplevels can be layered). |
| 2726 |
*/ |
| 2727 |
gboolean |
| 2728 |
_gdk_win32_window_lacks_wm_decorations (GdkWindow *window) |
| 2729 |
{ |
| 2730 |
GdkWindowImplWin32 *impl; |
| 2731 |
LONG style; |
| 2732 |
gboolean has_any_decorations; |
| 2733 |
|
| 2734 |
if (GDK_WINDOW_DESTROYED (window)) |
| 2735 |
return FALSE; |
| 2736 |
|
| 2737 |
/* only toplevels can be layered */ |
| 2738 |
if (!WINDOW_IS_TOPLEVEL (window)) |
| 2739 |
return FALSE; |
| 2740 |
|
| 2741 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2742 |
|
| 2743 |
/* This is because GTK calls gdk_window_set_decorations (window, 0), |
| 2744 |
* even though GdkWMDecoration docs indicate that 0 does NOT mean |
| 2745 |
* "no decorations". |
| 2746 |
*/ |
| 2747 |
if (impl->decorations && |
| 2748 |
*impl->decorations == 0) |
| 2749 |
return TRUE; |
| 2750 |
|
| 2751 |
if (GDK_WINDOW_HWND (window) == 0) |
| 2752 |
return FALSE; |
| 2753 |
|
| 2754 |
style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE); |
| 2755 |
|
| 2756 |
if (style == 0) |
| 2757 |
{ |
| 2758 |
DWORD w32_error = GetLastError (); |
| 2759 |
|
| 2760 |
GDK_NOTE (MISC, g_print ("Failed to get style of window %p (handle %p): %lu\n", |
| 2761 |
window, GDK_WINDOW_HWND (window), w32_error)); |
| 2762 |
return FALSE; |
| 2763 |
} |
| 2764 |
|
| 2765 |
/* Keep this in sync with _gdk_win32_window_update_style_bits() */ |
| 2766 |
/* We don't check what get_effective_window_decorations() |
| 2767 |
* has to say, because it gives suggestions based on |
| 2768 |
* various hints, while we want *actual* decorations, |
| 2769 |
* or their absence. |
| 2770 |
*/ |
| 2771 |
has_any_decorations = FALSE; |
| 2772 |
|
| 2773 |
if (style & (WS_BORDER | WS_THICKFRAME | WS_CAPTION)) |
| 2774 |
has_any_decorations = TRUE; |
| 2775 |
else |
| 2776 |
GDK_NOTE (MISC, g_print ("Window %p (handle %p): has no decorations (style %lx)\n", |
| 2777 |
window, GDK_WINDOW_HWND (window), style)); |
| 2778 |
|
| 2779 |
return !has_any_decorations; |
| 2780 |
} |
| 2781 |
|
| 2782 |
void |
| 2783 |
_gdk_win32_window_update_style_bits (GdkWindow *window) |
| 2784 |
{ |
| 2785 |
GdkWindowImplWin32 *impl = (GdkWindowImplWin32 *)window->impl; |
| 2786 |
GdkWMDecoration decorations; |
| 2787 |
LONG old_style, new_style, old_exstyle, new_exstyle; |
| 2788 |
gboolean needs_basic_layering = FALSE; |
| 2789 |
gboolean all; |
| 2790 |
RECT rect, before, after; |
| 2791 |
gboolean was_topmost; |
| 2792 |
gboolean will_be_topmost; |
| 2793 |
HWND insert_after; |
| 2794 |
UINT flags; |
| 2795 |
|
| 2796 |
if (window->state & GDK_WINDOW_STATE_FULLSCREEN) |
| 2797 |
return; |
| 2798 |
|
| 2799 |
old_style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE); |
| 2800 |
old_exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE); |
| 2801 |
|
| 2802 |
GetClientRect (GDK_WINDOW_HWND (window), &before); |
| 2803 |
after = before; |
| 2804 |
AdjustWindowRectEx (&before, old_style, FALSE, old_exstyle); |
| 2805 |
|
| 2806 |
was_topmost = (old_exstyle & WS_EX_TOPMOST) ? TRUE : FALSE; |
| 2807 |
will_be_topmost = was_topmost; |
| 2808 |
|
| 2809 |
old_exstyle &= ~WS_EX_TOPMOST; |
| 2810 |
|
| 2811 |
new_style = old_style; |
| 2812 |
new_exstyle = old_exstyle; |
| 2813 |
|
| 2814 |
if (window->window_type == GDK_WINDOW_TEMP) |
| 2815 |
{ |
| 2816 |
new_exstyle |= WS_EX_TOOLWINDOW; |
| 2817 |
will_be_topmost = TRUE; |
| 2818 |
} |
| 2819 |
else if (impl->type_hint == GDK_WINDOW_TYPE_HINT_UTILITY) |
| 2820 |
{ |
| 2821 |
new_exstyle |= WS_EX_TOOLWINDOW; |
| 2822 |
} |
| 2823 |
else |
| 2824 |
{ |
| 2825 |
new_exstyle &= ~WS_EX_TOOLWINDOW; |
| 2826 |
} |
| 2827 |
|
| 2828 |
/* We can get away with using layered windows |
| 2829 |
* only when no decorations are needed. It can mean |
| 2830 |
* CSD or borderless non-CSD windows (tooltips?). |
| 2831 |
* |
| 2832 |
* If this window cannot use layered windows, disable it always. |
| 2833 |
* This currently applies to windows using OpenGL, which |
| 2834 |
* does not work with layered windows. |
| 2835 |
*/ |
| 2836 |
if (impl->suppress_layered == 0) |
| 2837 |
{ |
| 2838 |
if (_gdk_win32_window_lacks_wm_decorations (window)) |
| 2839 |
impl->layered = g_strcmp0 (g_getenv ("GDK_WIN32_LAYERED"), "0") != 0; |
| 2840 |
} |
| 2841 |
else |
| 2842 |
impl->layered = FALSE; |
| 2843 |
|
| 2844 |
/* DND windows need to have the WS_EX_TRANSPARENT | WS_EX_LAYERED styles |
| 2845 |
* set so to behave in input passthrough mode. That's essential for DND |
| 2846 |
* indicators. |
| 2847 |
*/ |
| 2848 |
if (!impl->layered && |
| 2849 |
GDK_WINDOW_HWND (window) != NULL && |
| 2850 |
impl->type_hint == GDK_WINDOW_TYPE_HINT_DND) |
| 2851 |
{ |
| 2852 |
needs_basic_layering = TRUE; |
| 2853 |
} |
| 2854 |
|
| 2855 |
if (impl->layered || needs_basic_layering) |
| 2856 |
new_exstyle |= WS_EX_LAYERED; |
| 2857 |
else |
| 2858 |
new_exstyle &= ~WS_EX_LAYERED; |
| 2859 |
|
| 2860 |
if (get_effective_window_decorations (window, &decorations)) |
| 2861 |
{ |
| 2862 |
all = (decorations & GDK_DECOR_ALL); |
| 2863 |
/* Keep this in sync with the test in _gdk_win32_window_lacks_wm_decorations() */ |
| 2864 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_BORDER, WS_BORDER); |
| 2865 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_RESIZEH, WS_THICKFRAME); |
| 2866 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_TITLE, WS_CAPTION); |
| 2867 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_MENU, WS_SYSMENU); |
| 2868 |
if (impl->type_hint == GDK_WINDOW_TYPE_HINT_NORMAL) |
| 2869 |
{ |
| 2870 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_MINIMIZE, WS_MINIMIZEBOX); |
| 2871 |
update_single_bit (&new_style, all, decorations & GDK_DECOR_MAXIMIZE, WS_MAXIMIZEBOX); |
| 2872 |
} |
| 2873 |
} |
| 2874 |
|
| 2875 |
if (needs_basic_layering) |
| 2876 |
{ |
| 2877 |
/* SetLayeredWindowAttributes may have been already called, e.g. to set an opacity level. |
| 2878 |
* We only have to call the API in case it has never been called before on the window. |
| 2879 |
*/ |
| 2880 |
if (SetLastError(0), |
| 2881 |
!GetLayeredWindowAttributes (GDK_WINDOW_HWND (window), NULL, NULL, NULL) && |
| 2882 |
GetLastError() == 0) |
| 2883 |
{ |
| 2884 |
API_CALL (SetLayeredWindowAttributes, (GDK_WINDOW_HWND (window), 0, 255, LWA_ALPHA)); |
| 2885 |
} |
| 2886 |
} |
| 2887 |
|
| 2888 |
if (old_style == new_style && old_exstyle == new_exstyle ) |
| 2889 |
{ |
| 2890 |
GDK_NOTE (MISC, g_print ("_gdk_win32_window_update_style_bits: %p: no change\n", |
| 2891 |
GDK_WINDOW_HWND (window))); |
| 2892 |
return; |
| 2893 |
} |
| 2894 |
|
| 2895 |
if (old_style != new_style) |
| 2896 |
{ |
| 2897 |
GDK_NOTE (MISC, g_print ("_gdk_win32_window_update_style_bits: %p: STYLE: %s => %s\n", |
| 2898 |
GDK_WINDOW_HWND (window), |
| 2899 |
_gdk_win32_window_style_to_string (old_style), |
| 2900 |
_gdk_win32_window_style_to_string (new_style))); |
| 2901 |
|
| 2902 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, new_style); |
| 2903 |
} |
| 2904 |
|
| 2905 |
if (old_exstyle != new_exstyle) |
| 2906 |
{ |
| 2907 |
GDK_NOTE (MISC, g_print ("_gdk_win32_window_update_style_bits: %p: EXSTYLE: %s => %s\n", |
| 2908 |
GDK_WINDOW_HWND (window), |
| 2909 |
_gdk_win32_window_exstyle_to_string (old_exstyle), |
| 2910 |
_gdk_win32_window_exstyle_to_string (new_exstyle))); |
| 2911 |
|
| 2912 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE, new_exstyle); |
| 2913 |
} |
| 2914 |
|
| 2915 |
AdjustWindowRectEx (&after, new_style, FALSE, new_exstyle); |
| 2916 |
|
| 2917 |
GetWindowRect (GDK_WINDOW_HWND (window), &rect); |
| 2918 |
rect.left += after.left - before.left; |
| 2919 |
rect.top += after.top - before.top; |
| 2920 |
rect.right += after.right - before.right; |
| 2921 |
rect.bottom += after.bottom - before.bottom; |
| 2922 |
|
| 2923 |
flags = SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOREPOSITION; |
| 2924 |
|
| 2925 |
if (will_be_topmost && !was_topmost) |
| 2926 |
{ |
| 2927 |
insert_after = HWND_TOPMOST; |
| 2928 |
} |
| 2929 |
else if (was_topmost && !will_be_topmost) |
| 2930 |
{ |
| 2931 |
insert_after = HWND_NOTOPMOST; |
| 2932 |
} |
| 2933 |
else |
| 2934 |
{ |
| 2935 |
flags |= SWP_NOZORDER; |
| 2936 |
insert_after = SWP_NOZORDER_SPECIFIED; |
| 2937 |
} |
| 2938 |
|
| 2939 |
SetWindowPos (GDK_WINDOW_HWND (window), insert_after, |
| 2940 |
rect.left, rect.top, |
| 2941 |
rect.right - rect.left, rect.bottom - rect.top, |
| 2942 |
flags); |
| 2943 |
} |
| 2944 |
|
| 2945 |
static void |
| 2946 |
update_single_system_menu_entry (HMENU hmenu, |
| 2947 |
gboolean all, |
| 2948 |
int gdk_bit, |
| 2949 |
int menu_entry) |
| 2950 |
{ |
| 2951 |
/* all controls the interpretation of gdk_bit -- if all is TRUE, |
| 2952 |
* gdk_bit indicates whether menu entry is disabled; if all is |
| 2953 |
* FALSE, gdk bit indicate whether menu entry is enabled |
| 2954 |
*/ |
| 2955 |
if ((!all && gdk_bit) || (all && !gdk_bit)) |
| 2956 |
EnableMenuItem (hmenu, menu_entry, MF_BYCOMMAND | MF_ENABLED); |
| 2957 |
else |
| 2958 |
EnableMenuItem (hmenu, menu_entry, MF_BYCOMMAND | MF_GRAYED); |
| 2959 |
} |
| 2960 |
|
| 2961 |
static void |
| 2962 |
update_system_menu (GdkWindow *window) |
| 2963 |
{ |
| 2964 |
GdkWMFunction functions; |
| 2965 |
BOOL all; |
| 2966 |
|
| 2967 |
if (_gdk_window_get_functions (window, &functions)) |
| 2968 |
{ |
| 2969 |
HMENU hmenu = GetSystemMenu (GDK_WINDOW_HWND (window), FALSE); |
| 2970 |
|
| 2971 |
all = (functions & GDK_FUNC_ALL); |
| 2972 |
update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_RESIZE, SC_SIZE); |
| 2973 |
update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MOVE, SC_MOVE); |
| 2974 |
update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MINIMIZE, SC_MINIMIZE); |
| 2975 |
update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_MAXIMIZE, SC_MAXIMIZE); |
| 2976 |
update_single_system_menu_entry (hmenu, all, functions & GDK_FUNC_CLOSE, SC_CLOSE); |
| 2977 |
} |
| 2978 |
} |
| 2979 |
|
| 2980 |
static void |
| 2981 |
gdk_win32_window_set_decorations (GdkWindow *window, |
| 2982 |
GdkWMDecoration decorations) |
| 2983 |
{ |
| 2984 |
GdkWindowImplWin32 *impl; |
| 2985 |
|
| 2986 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 2987 |
|
| 2988 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2989 |
|
| 2990 |
GDK_NOTE (MISC, g_print ("gdk_window_set_decorations: %p: %s %s%s%s%s%s%s\n", |
| 2991 |
GDK_WINDOW_HWND (window), |
| 2992 |
(decorations & GDK_DECOR_ALL ? "clearing" : "setting"), |
| 2993 |
(decorations & GDK_DECOR_BORDER ? "BORDER " : ""), |
| 2994 |
(decorations & GDK_DECOR_RESIZEH ? "RESIZEH " : ""), |
| 2995 |
(decorations & GDK_DECOR_TITLE ? "TITLE " : ""), |
| 2996 |
(decorations & GDK_DECOR_MENU ? "MENU " : ""), |
| 2997 |
(decorations & GDK_DECOR_MINIMIZE ? "MINIMIZE " : ""), |
| 2998 |
(decorations & GDK_DECOR_MAXIMIZE ? "MAXIMIZE " : ""))); |
| 2999 |
|
| 3000 |
if (!impl->decorations) |
| 3001 |
impl->decorations = g_malloc (sizeof (GdkWMDecoration)); |
| 3002 |
|
| 3003 |
*impl->decorations = decorations; |
| 3004 |
|
| 3005 |
_gdk_win32_window_update_style_bits (window); |
| 3006 |
} |
| 3007 |
|
| 3008 |
static gboolean |
| 3009 |
gdk_win32_window_get_decorations (GdkWindow *window, |
| 3010 |
GdkWMDecoration *decorations) |
| 3011 |
{ |
| 3012 |
GdkWindowImplWin32 *impl; |
| 3013 |
|
| 3014 |
g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE); |
| 3015 |
|
| 3016 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3017 |
|
| 3018 |
if (impl->decorations == NULL) |
| 3019 |
return FALSE; |
| 3020 |
|
| 3021 |
*decorations = *impl->decorations; |
| 3022 |
|
| 3023 |
return TRUE; |
| 3024 |
} |
| 3025 |
|
| 3026 |
static GQuark |
| 3027 |
get_functions_quark () |
| 3028 |
{ |
| 3029 |
static GQuark quark = 0; |
| 3030 |
|
| 3031 |
if (!quark) |
| 3032 |
quark = g_quark_from_static_string ("gdk-window-functions"); |
| 3033 |
|
| 3034 |
return quark; |
| 3035 |
} |
| 3036 |
|
| 3037 |
static void |
| 3038 |
gdk_win32_window_set_functions (GdkWindow *window, |
| 3039 |
GdkWMFunction functions) |
| 3040 |
{ |
| 3041 |
GdkWMFunction* functions_copy; |
| 3042 |
|
| 3043 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 3044 |
|
| 3045 |
GDK_NOTE (MISC, g_print ("gdk_window_set_functions: %p: %s %s%s%s%s%s\n", |
| 3046 |
GDK_WINDOW_HWND (window), |
| 3047 |
(functions & GDK_FUNC_ALL ? "clearing" : "setting"), |
| 3048 |
(functions & GDK_FUNC_RESIZE ? "RESIZE " : ""), |
| 3049 |
(functions & GDK_FUNC_MOVE ? "MOVE " : ""), |
| 3050 |
(functions & GDK_FUNC_MINIMIZE ? "MINIMIZE " : ""), |
| 3051 |
(functions & GDK_FUNC_MAXIMIZE ? "MAXIMIZE " : ""), |
| 3052 |
(functions & GDK_FUNC_CLOSE ? "CLOSE " : ""))); |
| 3053 |
|
| 3054 |
functions_copy = g_malloc (sizeof (GdkWMFunction)); |
| 3055 |
*functions_copy = functions; |
| 3056 |
g_object_set_qdata_full (G_OBJECT (window), get_functions_quark (), functions_copy, g_free); |
| 3057 |
|
| 3058 |
update_system_menu (window); |
| 3059 |
} |
| 3060 |
|
| 3061 |
gboolean |
| 3062 |
_gdk_window_get_functions (GdkWindow *window, |
| 3063 |
GdkWMFunction *functions) |
| 3064 |
{ |
| 3065 |
GdkWMFunction* functions_set; |
| 3066 |
|
| 3067 |
functions_set = g_object_get_qdata (G_OBJECT (window), get_functions_quark ()); |
| 3068 |
if (functions_set) |
| 3069 |
*functions = *functions_set; |
| 3070 |
|
| 3071 |
return (functions_set != NULL); |
| 3072 |
} |
| 3073 |
|
| 3074 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3075 |
static void |
| 3076 |
log_region (gchar *prefix, AeroSnapEdgeRegion *region) |
| 3077 |
{ |
| 3078 |
GDK_NOTE (MISC, g_print ("Region %s:\n" |
| 3079 |
"edge %d x %d @ %d x %d\n" |
| 3080 |
"trig %d x %d @ %d x %d\n", |
| 3081 |
prefix, |
| 3082 |
region->edge.width, |
| 3083 |
region->edge.height, |
| 3084 |
region->edge.x, |
| 3085 |
region->edge.y, |
| 3086 |
region->trigger.width, |
| 3087 |
region->trigger.height, |
| 3088 |
region->trigger.x, |
| 3089 |
region->trigger.y)); |
| 3090 |
} |
| 3091 |
#endif |
| 3092 |
|
| 3093 |
static void |
| 3094 |
calculate_aerosnap_regions (GdkW32DragMoveResizeContext *context) |
| 3095 |
{ |
| 3096 |
GdkDisplay *display; |
| 3097 |
GdkScreen *screen; |
| 3098 |
gint n_monitors, monitor, other_monitor; |
| 3099 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (context->window->impl); |
| 3100 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3101 |
gint i; |
| 3102 |
#endif |
| 3103 |
|
| 3104 |
display = gdk_display_get_default (); |
| 3105 |
screen = gdk_display_get_default_screen (display); |
| 3106 |
n_monitors = gdk_screen_get_n_monitors (screen); |
| 3107 |
|
| 3108 |
#define _M_UP 0 |
| 3109 |
#define _M_DOWN 1 |
| 3110 |
#define _M_LEFT 2 |
| 3111 |
#define _M_RIGHT 3 |
| 3112 |
|
| 3113 |
for (monitor = 0; monitor < n_monitors; monitor++) |
| 3114 |
{ |
| 3115 |
GdkRectangle wa; |
| 3116 |
GdkRectangle geometry; |
| 3117 |
AeroSnapEdgeRegion snap_region; |
| 3118 |
gboolean move_edge[4] = { TRUE, FALSE, TRUE, TRUE }; |
| 3119 |
gboolean resize_edge[2] = { TRUE, TRUE }; |
| 3120 |
gint diff; |
| 3121 |
gint thickness, trigger_thickness; |
| 3122 |
|
| 3123 |
gdk_screen_get_monitor_workarea (screen, monitor, &wa); |
| 3124 |
gdk_screen_get_monitor_geometry (screen, monitor, &geometry); |
| 3125 |
|
| 3126 |
for (other_monitor = 0; |
| 3127 |
other_monitor < n_monitors && |
| 3128 |
(move_edge[_M_UP] || move_edge[_M_LEFT] || |
| 3129 |
move_edge[_M_RIGHT] || resize_edge[_M_DOWN]); |
| 3130 |
other_monitor++) |
| 3131 |
{ |
| 3132 |
GdkRectangle other_wa; |
| 3133 |
|
| 3134 |
if (other_monitor == monitor) |
| 3135 |
continue; |
| 3136 |
|
| 3137 |
gdk_screen_get_monitor_workarea (screen, other_monitor, &other_wa); |
| 3138 |
|
| 3139 |
/* An edge triggers AeroSnap only if there are no |
| 3140 |
* monitors beyond that edge. |
| 3141 |
* Even if there's another monitor, but it does not cover |
| 3142 |
* the whole edge (it's smaller or is not aligned to |
| 3143 |
* the corner of current monitor), that edge is still |
| 3144 |
* removed from the trigger list. |
| 3145 |
*/ |
| 3146 |
if (other_wa.x >= wa.x + wa.width) |
| 3147 |
move_edge[_M_RIGHT] = FALSE; |
| 3148 |
|
| 3149 |
if (other_wa.x + other_wa.width <= wa.x) |
| 3150 |
move_edge[_M_LEFT] = FALSE; |
| 3151 |
|
| 3152 |
if (other_wa.y + other_wa.height <= wa.y) |
| 3153 |
{ |
| 3154 |
move_edge[_M_UP] = FALSE; |
| 3155 |
resize_edge[_M_UP] = FALSE; |
| 3156 |
} |
| 3157 |
|
| 3158 |
if (other_wa.y >= wa.y + wa.height) |
| 3159 |
{ |
| 3160 |
/* no move_edge for the bottom edge, just resize_edge */ |
| 3161 |
resize_edge[_M_DOWN] = FALSE; |
| 3162 |
} |
| 3163 |
} |
| 3164 |
|
| 3165 |
thickness = AEROSNAP_REGION_THICKNESS * impl->window_scale; |
| 3166 |
trigger_thickness = AEROSNAP_REGION_TRIGGER_THICKNESS * impl->window_scale; |
| 3167 |
|
| 3168 |
snap_region.edge = wa; |
| 3169 |
snap_region.trigger = wa; |
| 3170 |
snap_region.edge.height = thickness; |
| 3171 |
snap_region.trigger.height = trigger_thickness; |
| 3172 |
|
| 3173 |
/* Extend both regions into toolbar space. |
| 3174 |
* When there's no toolbar, diff == 0. |
| 3175 |
*/ |
| 3176 |
diff = wa.y - geometry.y; |
| 3177 |
snap_region.edge.height += diff; |
| 3178 |
snap_region.edge.y -= diff; |
| 3179 |
snap_region.trigger.height += diff; |
| 3180 |
snap_region.trigger.y -= diff; |
| 3181 |
|
| 3182 |
if (move_edge[_M_UP]) |
| 3183 |
g_array_append_val (context->maximize_regions, snap_region); |
| 3184 |
|
| 3185 |
if (resize_edge[_M_UP]) |
| 3186 |
g_array_append_val (context->fullup_regions, snap_region); |
| 3187 |
|
| 3188 |
snap_region.edge = wa; |
| 3189 |
snap_region.trigger = wa; |
| 3190 |
snap_region.edge.width = thickness; |
| 3191 |
snap_region.trigger.width = trigger_thickness; |
| 3192 |
|
| 3193 |
diff = wa.x - geometry.x; |
| 3194 |
snap_region.edge.width += diff; |
| 3195 |
snap_region.edge.x -= diff; |
| 3196 |
snap_region.trigger.width += diff; |
| 3197 |
snap_region.trigger.x -= diff; |
| 3198 |
|
| 3199 |
if (move_edge[_M_LEFT]) |
| 3200 |
g_array_append_val (context->halfleft_regions, snap_region); |
| 3201 |
|
| 3202 |
snap_region.edge = wa; |
| 3203 |
snap_region.trigger = wa; |
| 3204 |
snap_region.edge.x += wa.width - thickness; |
| 3205 |
snap_region.edge.width = thickness; |
| 3206 |
snap_region.trigger.x += wa.width - trigger_thickness; |
| 3207 |
snap_region.trigger.width = trigger_thickness; |
| 3208 |
|
| 3209 |
diff = (geometry.x + geometry.width) - (wa.x + wa.width); |
| 3210 |
snap_region.edge.width += diff; |
| 3211 |
snap_region.trigger.width += diff; |
| 3212 |
|
| 3213 |
if (move_edge[_M_RIGHT]) |
| 3214 |
g_array_append_val (context->halfright_regions, snap_region); |
| 3215 |
|
| 3216 |
snap_region.edge = wa; |
| 3217 |
snap_region.trigger = wa; |
| 3218 |
snap_region.edge.y += wa.height - thickness; |
| 3219 |
snap_region.edge.height = thickness; |
| 3220 |
snap_region.trigger.y += wa.height - trigger_thickness; |
| 3221 |
snap_region.trigger.height = trigger_thickness; |
| 3222 |
|
| 3223 |
diff = (geometry.y + geometry.height) - (wa.y + wa.height); |
| 3224 |
snap_region.edge.height += diff; |
| 3225 |
snap_region.trigger.height += diff; |
| 3226 |
|
| 3227 |
if (resize_edge[_M_DOWN]) |
| 3228 |
g_array_append_val (context->fullup_regions, snap_region); |
| 3229 |
} |
| 3230 |
|
| 3231 |
#undef _M_UP |
| 3232 |
#undef _M_DOWN |
| 3233 |
#undef _M_LEFT |
| 3234 |
#undef _M_RIGHT |
| 3235 |
|
| 3236 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3237 |
for (i = 0; i < context->maximize_regions->len; i++) |
| 3238 |
log_region ("maximize", &g_array_index (context->maximize_regions, AeroSnapEdgeRegion, i)); |
| 3239 |
|
| 3240 |
for (i = 0; i < context->halfleft_regions->len; i++) |
| 3241 |
log_region ("halfleft", &g_array_index (context->halfleft_regions, AeroSnapEdgeRegion, i)); |
| 3242 |
|
| 3243 |
for (i = 0; i < context->halfright_regions->len; i++) |
| 3244 |
log_region ("halfright", &g_array_index (context->halfright_regions, AeroSnapEdgeRegion, i)); |
| 3245 |
|
| 3246 |
for (i = 0; i < context->fullup_regions->len; i++) |
| 3247 |
log_region ("fullup", &g_array_index (context->fullup_regions, AeroSnapEdgeRegion, i)); |
| 3248 |
#endif |
| 3249 |
} |
| 3250 |
|
| 3251 |
static void |
| 3252 |
discard_snapinfo (GdkWindow *window) |
| 3253 |
{ |
| 3254 |
GdkWindowImplWin32 *impl; |
| 3255 |
|
| 3256 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3257 |
|
| 3258 |
impl->snap_state = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 3259 |
|
| 3260 |
if (impl->snap_stash == NULL) |
| 3261 |
return; |
| 3262 |
|
| 3263 |
g_clear_pointer (&impl->snap_stash, g_free); |
| 3264 |
g_clear_pointer (&impl->snap_stash_int, g_free); |
| 3265 |
} |
| 3266 |
|
| 3267 |
static void |
| 3268 |
unsnap (GdkWindow *window, |
| 3269 |
GdkScreen *screen, |
| 3270 |
gint monitor) |
| 3271 |
{ |
| 3272 |
GdkWindowImplWin32 *impl; |
| 3273 |
GdkRectangle rect; |
| 3274 |
|
| 3275 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3276 |
|
| 3277 |
impl->snap_state = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 3278 |
|
| 3279 |
if (impl->snap_stash == NULL) |
| 3280 |
return; |
| 3281 |
|
| 3282 |
gdk_screen_get_monitor_workarea (screen, monitor, &rect); |
| 3283 |
|
| 3284 |
GDK_NOTE (MISC, g_print ("Monitor work area %d x %d @ %d : %d\n", rect.width, rect.height, rect.x, rect.y)); |
| 3285 |
|
| 3286 |
if (rect.width >= impl->snap_stash_int->width && |
| 3287 |
rect.height >= impl->snap_stash_int->height) |
| 3288 |
{ |
| 3289 |
/* If the window fits into new work area without resizing it, |
| 3290 |
* place it into new work area without resizing it. |
| 3291 |
*/ |
| 3292 |
gdouble left, right, up, down, hratio, vratio; |
| 3293 |
gdouble hscale, vscale; |
| 3294 |
gdouble new_left, new_up; |
| 3295 |
|
| 3296 |
left = impl->snap_stash->x; |
| 3297 |
right = 1.0 - (impl->snap_stash->x + impl->snap_stash->width); |
| 3298 |
up = impl->snap_stash->y; |
| 3299 |
down = 1.0 - (impl->snap_stash->y + impl->snap_stash->height); |
| 3300 |
hscale = 1.0; |
| 3301 |
|
| 3302 |
if (right > 0.001) |
| 3303 |
{ |
| 3304 |
hratio = left / right; |
| 3305 |
hscale = hratio / (1.0 + hratio); |
| 3306 |
} |
| 3307 |
|
| 3308 |
new_left = (gdouble) (rect.width - impl->snap_stash_int->width) * hscale; |
| 3309 |
|
| 3310 |
vscale = 1.0; |
| 3311 |
|
| 3312 |
if (down > 0.001) |
| 3313 |
{ |
| 3314 |
vratio = up / down; |
| 3315 |
vscale = vratio / (1.0 + vratio); |
| 3316 |
} |
| 3317 |
|
| 3318 |
new_up = (gdouble) (rect.height - impl->snap_stash_int->height) * vscale; |
| 3319 |
|
| 3320 |
rect.x = round (rect.x + new_left); |
| 3321 |
rect.y = round (rect.y + new_up); |
| 3322 |
rect.width = impl->snap_stash_int->width; |
| 3323 |
rect.height = impl->snap_stash_int->height; |
| 3324 |
} |
| 3325 |
else |
| 3326 |
{ |
| 3327 |
/* Calculate actual unsnapped window size based on its |
| 3328 |
* old relative size. Same for position. |
| 3329 |
*/ |
| 3330 |
rect.x += round (rect.width * impl->snap_stash->x); |
| 3331 |
rect.y += round (rect.height * impl->snap_stash->y); |
| 3332 |
rect.width = round (rect.width * impl->snap_stash->width); |
| 3333 |
rect.height = round (rect.height * impl->snap_stash->height); |
| 3334 |
} |
| 3335 |
|
| 3336 |
GDK_NOTE (MISC, g_print ("Unsnapped window size %d x %d @ %d : %d\n", rect.width, rect.height, rect.x, rect.y)); |
| 3337 |
|
| 3338 |
gdk_window_move_resize (window, rect.x, rect.y, |
| 3339 |
rect.width, rect.height); |
| 3340 |
|
| 3341 |
g_clear_pointer (&impl->snap_stash, g_free); |
| 3342 |
g_clear_pointer (&impl->snap_stash_int, g_free); |
| 3343 |
} |
| 3344 |
|
| 3345 |
static void |
| 3346 |
stash_window (GdkWindow *window, |
| 3347 |
GdkWindowImplWin32 *impl, |
| 3348 |
GdkScreen *screen, |
| 3349 |
gint monitor) |
| 3350 |
{ |
| 3351 |
gint x, y; |
| 3352 |
gint width, wwidth; |
| 3353 |
gint height, wheight; |
| 3354 |
WINDOWPLACEMENT placement; |
| 3355 |
HMONITOR hmonitor; |
| 3356 |
MONITORINFO hmonitor_info; |
| 3357 |
|
| 3358 |
placement.length = sizeof(WINDOWPLACEMENT); |
| 3359 |
|
| 3360 |
/* Use W32 API to get unmaximized window size, which GDK doesn't remember */ |
| 3361 |
if (!GetWindowPlacement (GDK_WINDOW_HWND (window), &placement)) |
| 3362 |
return; |
| 3363 |
|
| 3364 |
/* MSDN is very vague, but in practice rcNormalPosition is the same as GetWindowRect(), |
| 3365 |
* only with adjustments for toolbars (which creates rather weird coodinate space issues). |
| 3366 |
* We need to get monitor info and apply workarea vs monitorarea diff to turn |
| 3367 |
* these into screen coordinates proper. |
| 3368 |
*/ |
| 3369 |
hmonitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST); |
| 3370 |
hmonitor_info.cbSize = sizeof (hmonitor_info); |
| 3371 |
|
| 3372 |
if (!GetMonitorInfoA (hmonitor, &hmonitor_info)) |
| 3373 |
return; |
| 3374 |
|
| 3375 |
if (impl->snap_stash == NULL) |
| 3376 |
impl->snap_stash = g_new0 (GdkRectangleDouble, 1); |
| 3377 |
|
| 3378 |
if (impl->snap_stash_int == NULL) |
| 3379 |
impl->snap_stash_int = g_new0 (GdkRectangle, 1); |
| 3380 |
|
| 3381 |
GDK_NOTE (MISC, g_print ("monitor work area %ld x %ld @ %ld : %ld\n", |
| 3382 |
(hmonitor_info.rcWork.right - hmonitor_info.rcWork.left) / impl->window_scale, |
| 3383 |
(hmonitor_info.rcWork.bottom - hmonitor_info.rcWork.top) / impl->window_scale, |
| 3384 |
hmonitor_info.rcWork.left, |
| 3385 |
hmonitor_info.rcWork.top)); |
| 3386 |
GDK_NOTE (MISC, g_print ("monitor area %ld x %ld @ %ld : %ld\n", |
| 3387 |
(hmonitor_info.rcMonitor.right - hmonitor_info.rcMonitor.left) / impl->window_scale, |
| 3388 |
(hmonitor_info.rcMonitor.bottom - hmonitor_info.rcMonitor.top) / impl->window_scale, |
| 3389 |
hmonitor_info.rcMonitor.left, |
| 3390 |
hmonitor_info.rcMonitor.top)); |
| 3391 |
GDK_NOTE (MISC, g_print ("window work place %ld x %ld @ %ld : %ld\n", |
| 3392 |
(placement.rcNormalPosition.right - placement.rcNormalPosition.left) / impl->window_scale, |
| 3393 |
(placement.rcNormalPosition.bottom - placement.rcNormalPosition.top) / impl->window_scale, |
| 3394 |
placement.rcNormalPosition.left, |
| 3395 |
placement.rcNormalPosition.top)); |
| 3396 |
|
| 3397 |
width = (placement.rcNormalPosition.right - placement.rcNormalPosition.left) / impl->window_scale; |
| 3398 |
height = (placement.rcNormalPosition.bottom - placement.rcNormalPosition.top) / impl->window_scale; |
| 3399 |
x = (placement.rcNormalPosition.left - hmonitor_info.rcMonitor.left) / impl->window_scale; |
| 3400 |
y = (placement.rcNormalPosition.top - hmonitor_info.rcMonitor.top) / impl->window_scale; |
| 3401 |
|
| 3402 |
wwidth = (hmonitor_info.rcWork.right - hmonitor_info.rcWork.left) / impl->window_scale; |
| 3403 |
wheight = (hmonitor_info.rcWork.bottom - hmonitor_info.rcWork.top) / impl->window_scale; |
| 3404 |
|
| 3405 |
impl->snap_stash->x = (gdouble) (x) / (gdouble) (wwidth); |
| 3406 |
impl->snap_stash->y = (gdouble) (y) / (gdouble) (wheight); |
| 3407 |
impl->snap_stash->width = (gdouble) width / (gdouble) (wwidth); |
| 3408 |
impl->snap_stash->height = (gdouble) height / (gdouble) (wheight); |
| 3409 |
|
| 3410 |
impl->snap_stash_int->x = x; |
| 3411 |
impl->snap_stash_int->y = y; |
| 3412 |
impl->snap_stash_int->width = width; |
| 3413 |
impl->snap_stash_int->height = height; |
| 3414 |
|
| 3415 |
GDK_NOTE (MISC, g_print ("Stashed window %d x %d @ %d : %d as %f x %f @ %f : %f\n", |
| 3416 |
width, height, x, y, |
| 3417 |
impl->snap_stash->width, impl->snap_stash->height, impl->snap_stash->x, impl->snap_stash->y)); |
| 3418 |
} |
| 3419 |
|
| 3420 |
static void |
| 3421 |
snap_up (GdkWindow *window, |
| 3422 |
GdkScreen *screen, |
| 3423 |
gint monitor) |
| 3424 |
{ |
| 3425 |
SHORT maxysize; |
| 3426 |
gint x, y; |
| 3427 |
gint width, height; |
| 3428 |
GdkWindowImplWin32 *impl; |
| 3429 |
|
| 3430 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3431 |
|
| 3432 |
impl->snap_state = GDK_WIN32_AEROSNAP_STATE_FULLUP; |
| 3433 |
|
| 3434 |
stash_window (window, impl, screen, monitor); |
| 3435 |
|
| 3436 |
maxysize = GetSystemMetrics (SM_CYVIRTUALSCREEN) / impl->window_scale; |
| 3437 |
gdk_window_get_position (window, &x, &y); |
| 3438 |
width = gdk_window_get_width (window); |
| 3439 |
|
| 3440 |
y = 0; |
| 3441 |
height = maxysize; |
| 3442 |
|
| 3443 |
x = x - impl->margins.left; |
| 3444 |
y = y - impl->margins.top; |
| 3445 |
width += impl->margins_x; |
| 3446 |
height += impl->margins_y; |
| 3447 |
|
| 3448 |
gdk_window_move_resize (window, x, y, width, height); |
| 3449 |
} |
| 3450 |
|
| 3451 |
static void |
| 3452 |
snap_left (GdkWindow *window, |
| 3453 |
GdkScreen *screen, |
| 3454 |
gint monitor, |
| 3455 |
gint snap_monitor) |
| 3456 |
{ |
| 3457 |
GdkRectangle rect; |
| 3458 |
GdkWindowImplWin32 *impl; |
| 3459 |
|
| 3460 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3461 |
|
| 3462 |
impl->snap_state = GDK_WIN32_AEROSNAP_STATE_HALFLEFT; |
| 3463 |
|
| 3464 |
gdk_screen_get_monitor_workarea (screen, snap_monitor, &rect); |
| 3465 |
|
| 3466 |
stash_window (window, impl, screen, monitor); |
| 3467 |
|
| 3468 |
rect.width = rect.width / 2; |
| 3469 |
|
| 3470 |
rect.x = rect.x - impl->margins.left; |
| 3471 |
rect.y = rect.y - impl->margins.top; |
| 3472 |
rect.width = rect.width + impl->margins_x; |
| 3473 |
rect.height = rect.height + impl->margins_y; |
| 3474 |
|
| 3475 |
gdk_window_move_resize (window, rect.x, rect.y, rect.width, rect.height); |
| 3476 |
} |
| 3477 |
|
| 3478 |
static void |
| 3479 |
snap_right (GdkWindow *window, |
| 3480 |
GdkScreen *screen, |
| 3481 |
gint monitor, |
| 3482 |
gint snap_monitor) |
| 3483 |
{ |
| 3484 |
GdkRectangle rect; |
| 3485 |
GdkWindowImplWin32 *impl; |
| 3486 |
|
| 3487 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3488 |
|
| 3489 |
impl->snap_state = GDK_WIN32_AEROSNAP_STATE_HALFRIGHT; |
| 3490 |
|
| 3491 |
gdk_screen_get_monitor_workarea (screen, snap_monitor, &rect); |
| 3492 |
|
| 3493 |
stash_window (window, impl, screen, monitor); |
| 3494 |
|
| 3495 |
rect.width = rect.width / 2; |
| 3496 |
rect.x += rect.width; |
| 3497 |
|
| 3498 |
rect.x = rect.x - impl->margins.left; |
| 3499 |
rect.y = rect.y - impl->margins.top; |
| 3500 |
rect.width = rect.width + impl->margins_x; |
| 3501 |
rect.height = rect.height + impl->margins_y; |
| 3502 |
|
| 3503 |
gdk_window_move_resize (window, rect.x, rect.y, rect.width, rect.height); |
| 3504 |
} |
| 3505 |
|
| 3506 |
void |
| 3507 |
_gdk_win32_window_handle_aerosnap (GdkWindow *window, |
| 3508 |
GdkWin32AeroSnapCombo combo) |
| 3509 |
{ |
| 3510 |
GdkWindowImplWin32 *impl; |
| 3511 |
GdkDisplay *display; |
| 3512 |
GdkScreen *screen; |
| 3513 |
gint n_monitors, monitor; |
| 3514 |
GdkWindowState window_state = gdk_window_get_state (window); |
| 3515 |
gboolean minimized = window_state & GDK_WINDOW_STATE_ICONIFIED; |
| 3516 |
gboolean maximized = window_state & GDK_WINDOW_STATE_MAXIMIZED; |
| 3517 |
gboolean halfsnapped; |
| 3518 |
|
| 3519 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 3520 |
display = gdk_window_get_display (window); |
| 3521 |
screen = gdk_display_get_default_screen (display); |
| 3522 |
n_monitors = gdk_screen_get_n_monitors (screen); |
| 3523 |
monitor = gdk_screen_get_monitor_at_window (screen, window); |
| 3524 |
|
| 3525 |
if (minimized && maximized) |
| 3526 |
minimized = FALSE; |
| 3527 |
|
| 3528 |
halfsnapped = (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFRIGHT || |
| 3529 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFLEFT || |
| 3530 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_FULLUP); |
| 3531 |
|
| 3532 |
switch (combo) |
| 3533 |
{ |
| 3534 |
case GDK_WIN32_AEROSNAP_COMBO_NOTHING: |
| 3535 |
/* Do nothing */ |
| 3536 |
break; |
| 3537 |
case GDK_WIN32_AEROSNAP_COMBO_UP: |
| 3538 |
if (!maximized) |
| 3539 |
{ |
| 3540 |
unsnap (window, screen, monitor); |
| 3541 |
gdk_window_maximize (window); |
| 3542 |
} |
| 3543 |
break; |
| 3544 |
case GDK_WIN32_AEROSNAP_COMBO_DOWN: |
| 3545 |
case GDK_WIN32_AEROSNAP_COMBO_SHIFTDOWN: |
| 3546 |
if (maximized) |
| 3547 |
{ |
| 3548 |
gdk_window_unmaximize (window); |
| 3549 |
unsnap (window, screen, monitor); |
| 3550 |
} |
| 3551 |
else if (halfsnapped) |
| 3552 |
unsnap (window, screen, monitor); |
| 3553 |
else if (!minimized) |
| 3554 |
gdk_window_iconify (window); |
| 3555 |
break; |
| 3556 |
case GDK_WIN32_AEROSNAP_COMBO_LEFT: |
| 3557 |
if (maximized) |
| 3558 |
gdk_window_unmaximize (window); |
| 3559 |
|
| 3560 |
if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_UNDETERMINED || |
| 3561 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_FULLUP) |
| 3562 |
{ |
| 3563 |
unsnap (window, screen, monitor); |
| 3564 |
snap_left (window, screen, monitor, monitor); |
| 3565 |
} |
| 3566 |
else if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFLEFT) |
| 3567 |
{ |
| 3568 |
unsnap (window, screen, monitor); |
| 3569 |
snap_right (window, screen, monitor, monitor - 1 >= 0 ? monitor - 1 : n_monitors - 1); |
| 3570 |
} |
| 3571 |
else if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFRIGHT) |
| 3572 |
{ |
| 3573 |
unsnap (window, screen, monitor); |
| 3574 |
} |
| 3575 |
break; |
| 3576 |
case GDK_WIN32_AEROSNAP_COMBO_RIGHT: |
| 3577 |
if (maximized) |
| 3578 |
gdk_window_unmaximize (window); |
| 3579 |
|
| 3580 |
if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_UNDETERMINED || |
| 3581 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_FULLUP) |
| 3582 |
{ |
| 3583 |
unsnap (window, screen, monitor); |
| 3584 |
snap_right (window, screen, monitor, monitor); |
| 3585 |
} |
| 3586 |
else if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFLEFT) |
| 3587 |
{ |
| 3588 |
unsnap (window, screen, monitor); |
| 3589 |
} |
| 3590 |
else if (impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFRIGHT) |
| 3591 |
{ |
| 3592 |
unsnap (window, screen, monitor); |
| 3593 |
snap_left (window, screen, monitor, monitor + 1 < n_monitors ? monitor + 1 : 0); |
| 3594 |
} |
| 3595 |
break; |
| 3596 |
case GDK_WIN32_AEROSNAP_COMBO_SHIFTUP: |
| 3597 |
if (!maximized && |
| 3598 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_UNDETERMINED) |
| 3599 |
{ |
| 3600 |
snap_up (window, screen, monitor); |
| 3601 |
} |
| 3602 |
break; |
| 3603 |
case GDK_WIN32_AEROSNAP_COMBO_SHIFTLEFT: |
| 3604 |
case GDK_WIN32_AEROSNAP_COMBO_SHIFTRIGHT: |
| 3605 |
/* No implementation needed at the moment */ |
| 3606 |
break; |
| 3607 |
} |
| 3608 |
} |
| 3609 |
|
| 3610 |
static void |
| 3611 |
apply_snap (GdkWindow *window, |
| 3612 |
GdkWin32AeroSnapState snap) |
| 3613 |
{ |
| 3614 |
GdkScreen *screen; |
| 3615 |
gint monitor; |
| 3616 |
|
| 3617 |
screen = gdk_display_get_default_screen (gdk_window_get_display (window)); |
| 3618 |
monitor = gdk_screen_get_monitor_at_window (screen, window); |
| 3619 |
|
| 3620 |
switch (snap) |
| 3621 |
{ |
| 3622 |
case GDK_WIN32_AEROSNAP_STATE_UNDETERMINED: |
| 3623 |
break; |
| 3624 |
case GDK_WIN32_AEROSNAP_STATE_MAXIMIZE: |
| 3625 |
unsnap (window, screen, monitor); |
| 3626 |
gdk_window_maximize (window); |
| 3627 |
break; |
| 3628 |
case GDK_WIN32_AEROSNAP_STATE_HALFLEFT: |
| 3629 |
unsnap (window, screen, monitor); |
| 3630 |
snap_left (window, screen, monitor, monitor); |
| 3631 |
break; |
| 3632 |
case GDK_WIN32_AEROSNAP_STATE_HALFRIGHT: |
| 3633 |
unsnap (window, screen, monitor); |
| 3634 |
snap_right (window, screen, monitor, monitor); |
| 3635 |
break; |
| 3636 |
case GDK_WIN32_AEROSNAP_STATE_FULLUP: |
| 3637 |
snap_up (window, screen, monitor); |
| 3638 |
break; |
| 3639 |
} |
| 3640 |
} |
| 3641 |
|
| 3642 |
/* Registers a dumb window class. This window |
| 3643 |
* has DefWindowProc() for a window procedure and |
| 3644 |
* does not do anything that GdkWindow-bound HWNDs do. |
| 3645 |
*/ |
| 3646 |
static ATOM |
| 3647 |
RegisterGdkDumbClass () |
| 3648 |
{ |
| 3649 |
static ATOM klassDUMB = 0; |
| 3650 |
static WNDCLASSEXW wcl; |
| 3651 |
ATOM klass = 0; |
| 3652 |
|
| 3653 |
wcl.cbSize = sizeof (WNDCLASSEX); |
| 3654 |
wcl.style = 0; /* DON'T set CS_<H,V>REDRAW. It causes total redraw |
| 3655 |
* on WM_SIZE and WM_MOVE. Flicker, Performance! |
| 3656 |
*/ |
| 3657 |
wcl.lpfnWndProc = DefWindowProcW; |
| 3658 |
wcl.cbClsExtra = 0; |
| 3659 |
wcl.cbWndExtra = 0; |
| 3660 |
wcl.hInstance = _gdk_app_hmodule; |
| 3661 |
wcl.hIcon = 0; |
| 3662 |
wcl.hIconSm = 0; |
| 3663 |
wcl.lpszMenuName = NULL; |
| 3664 |
wcl.hbrBackground = NULL; |
| 3665 |
wcl.hCursor = LoadCursor (NULL, IDC_ARROW); |
| 3666 |
wcl.style |= CS_OWNDC; |
| 3667 |
wcl.lpszClassName = L"gdkWindowDumb"; |
| 3668 |
|
| 3669 |
if (klassDUMB == 0) |
| 3670 |
klassDUMB = RegisterClassExW (&wcl); |
| 3671 |
|
| 3672 |
klass = klassDUMB; |
| 3673 |
|
| 3674 |
if (klass == 0) |
| 3675 |
{ |
| 3676 |
WIN32_API_FAILED ("RegisterClassExW"); |
| 3677 |
g_error ("That is a fatal error"); |
| 3678 |
} |
| 3679 |
|
| 3680 |
return klass; |
| 3681 |
} |
| 3682 |
|
| 3683 |
static gboolean |
| 3684 |
ensure_snap_indicator_exists (GdkW32DragMoveResizeContext *context) |
| 3685 |
{ |
| 3686 |
if (context->shape_indicator == NULL) |
| 3687 |
{ |
| 3688 |
HWND handle; |
| 3689 |
ATOM klass; |
| 3690 |
klass = RegisterGdkDumbClass (); |
| 3691 |
|
| 3692 |
handle = CreateWindowExW (WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE, |
| 3693 |
MAKEINTRESOURCEW (klass), |
| 3694 |
L"", |
| 3695 |
WS_POPUP, |
| 3696 |
0, |
| 3697 |
0, |
| 3698 |
0, 0, |
| 3699 |
NULL, |
| 3700 |
NULL, |
| 3701 |
_gdk_app_hmodule, |
| 3702 |
NULL); |
| 3703 |
|
| 3704 |
context->shape_indicator = handle; |
| 3705 |
} |
| 3706 |
|
| 3707 |
return context->shape_indicator != NULL; |
| 3708 |
} |
| 3709 |
|
| 3710 |
static gboolean |
| 3711 |
ensure_snap_indicator_surface (GdkW32DragMoveResizeContext *context, |
| 3712 |
gint width, |
| 3713 |
gint height, |
| 3714 |
guint scale) |
| 3715 |
{ |
| 3716 |
if (context->indicator_surface != NULL && |
| 3717 |
(context->indicator_surface_width < width || |
| 3718 |
context->indicator_surface_height < height)) |
| 3719 |
{ |
| 3720 |
cairo_surface_destroy (context->indicator_surface); |
| 3721 |
context->indicator_surface = NULL; |
| 3722 |
} |
| 3723 |
|
| 3724 |
if (context->indicator_surface == NULL) |
| 3725 |
context->indicator_surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, |
| 3726 |
width * scale, |
| 3727 |
height * scale); |
| 3728 |
|
| 3729 |
if (cairo_surface_status (context->indicator_surface) != CAIRO_STATUS_SUCCESS) |
| 3730 |
{ |
| 3731 |
cairo_surface_destroy (context->indicator_surface); |
| 3732 |
context->indicator_surface = NULL; |
| 3733 |
|
| 3734 |
return FALSE; |
| 3735 |
} |
| 3736 |
|
| 3737 |
return TRUE; |
| 3738 |
} |
| 3739 |
|
| 3740 |
/* Indicator is drawn with some inward offset, so that it does |
| 3741 |
* not hug screen edges. |
| 3742 |
*/ |
| 3743 |
static void |
| 3744 |
adjust_indicator_rectangle (GdkRectangle *rect, |
| 3745 |
gboolean inward) |
| 3746 |
{ |
| 3747 |
gdouble inverter; |
| 3748 |
const gint gap = AEROSNAP_INDICATOR_EDGE_GAP; |
| 3749 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3750 |
GdkRectangle cache = *rect; |
| 3751 |
#endif |
| 3752 |
|
| 3753 |
if (inward) |
| 3754 |
inverter = 1.0; |
| 3755 |
else |
| 3756 |
inverter = -1.0; |
| 3757 |
|
| 3758 |
rect->x += (gap * inverter); |
| 3759 |
rect->y += (gap * inverter); |
| 3760 |
rect->width -= (gap * 2 * inverter); |
| 3761 |
rect->height -= (gap * 2 * inverter); |
| 3762 |
|
| 3763 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3764 |
GDK_NOTE (MISC, g_print ("Adjusted %d x %d @ %d : %d -> %d x %d @ %d : %d\n", |
| 3765 |
cache.width, cache.height, cache.x, cache.y, |
| 3766 |
rect->width, rect->height, rect->x, rect->y)); |
| 3767 |
#endif |
| 3768 |
} |
| 3769 |
|
| 3770 |
static void |
| 3771 |
rounded_rectangle (cairo_t *cr, |
| 3772 |
gint x, |
| 3773 |
gint y, |
| 3774 |
gint width, |
| 3775 |
gint height, |
| 3776 |
gdouble radius, |
| 3777 |
gdouble line_width, |
| 3778 |
GdkRGBA *fill, |
| 3779 |
GdkRGBA *outline) |
| 3780 |
{ |
| 3781 |
gdouble degrees = M_PI / 180.0; |
| 3782 |
|
| 3783 |
if (fill == NULL && outline == NULL) |
| 3784 |
return; |
| 3785 |
|
| 3786 |
cairo_save (cr); |
| 3787 |
cairo_new_sub_path (cr); |
| 3788 |
cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees); |
| 3789 |
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees); |
| 3790 |
cairo_arc (cr, (x + radius), y + height - radius, radius, 90 * degrees, 180 * degrees); |
| 3791 |
cairo_arc (cr, (x + radius), (y + radius), radius, 180 * degrees, 270 * degrees); |
| 3792 |
cairo_close_path (cr); |
| 3793 |
|
| 3794 |
if (fill) |
| 3795 |
{ |
| 3796 |
cairo_set_source_rgba (cr, fill->red, fill->green, fill->blue, fill->alpha); |
| 3797 |
|
| 3798 |
if (outline) |
| 3799 |
cairo_fill_preserve (cr); |
| 3800 |
else |
| 3801 |
cairo_fill (cr); |
| 3802 |
} |
| 3803 |
|
| 3804 |
if (outline) |
| 3805 |
{ |
| 3806 |
cairo_set_source_rgba (cr, outline->red, outline->green, outline->blue, outline->alpha); |
| 3807 |
cairo_set_line_width (cr, line_width); |
| 3808 |
cairo_stroke (cr); |
| 3809 |
} |
| 3810 |
|
| 3811 |
cairo_restore (cr); |
| 3812 |
} |
| 3813 |
|
| 3814 |
/* Translates linear animation scale into some kind of curve */ |
| 3815 |
static gdouble |
| 3816 |
curve (gdouble val) |
| 3817 |
{ |
| 3818 |
/* TODO: try different curves. For now it's just linear */ |
| 3819 |
return val; |
| 3820 |
} |
| 3821 |
|
| 3822 |
static gboolean |
| 3823 |
draw_indicator (GdkW32DragMoveResizeContext *context, |
| 3824 |
gint64 timestamp) |
| 3825 |
{ |
| 3826 |
cairo_t *cr; |
| 3827 |
GdkRGBA outline = {0, 0, 1.0, 1.0}; |
| 3828 |
GdkRGBA fill = {0, 0, 1.0, 0.8}; |
| 3829 |
GdkRectangle current_rect; |
| 3830 |
gint64 current_time = g_get_monotonic_time (); |
| 3831 |
gdouble animation_progress; |
| 3832 |
gboolean last_draw; |
| 3833 |
gdouble line_width; |
| 3834 |
gdouble corner_radius; |
| 3835 |
gint64 animation_duration; |
| 3836 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (context->window->impl); |
| 3837 |
|
| 3838 |
line_width = AEROSNAP_INDICATOR_LINE_WIDTH * impl->window_scale; |
| 3839 |
corner_radius = AEROSNAP_INDICATOR_CORNER_RADIUS; |
| 3840 |
animation_duration = AEROSNAP_INDICATOR_ANIMATION_DURATION; |
| 3841 |
last_draw = FALSE; |
| 3842 |
|
| 3843 |
if (timestamp == 0 && |
| 3844 |
current_time - context->indicator_start_time > animation_duration) |
| 3845 |
{ |
| 3846 |
timestamp = context->indicator_start_time + animation_duration; |
| 3847 |
last_draw = TRUE; |
| 3848 |
} |
| 3849 |
|
| 3850 |
if (timestamp != 0) |
| 3851 |
current_time = timestamp; |
| 3852 |
|
| 3853 |
animation_progress = (gdouble) (current_time - context->indicator_start_time) / animation_duration; |
| 3854 |
|
| 3855 |
if (animation_progress > 1.0) |
| 3856 |
animation_progress = 1.0; |
| 3857 |
|
| 3858 |
if (animation_progress < 0) |
| 3859 |
animation_progress = 0; |
| 3860 |
|
| 3861 |
animation_progress = curve (animation_progress); |
| 3862 |
|
| 3863 |
current_rect = context->indicator_start; |
| 3864 |
current_rect.x += (context->indicator_target.x - context->indicator_start.x) * animation_progress; |
| 3865 |
current_rect.y += (context->indicator_target.y - context->indicator_start.y) * animation_progress; |
| 3866 |
current_rect.width += (context->indicator_target.width - context->indicator_start.width) * animation_progress; |
| 3867 |
current_rect.height += (context->indicator_target.height - context->indicator_start.height) * animation_progress; |
| 3868 |
|
| 3869 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE && last_draw) |
| 3870 |
{ |
| 3871 |
switch (context->edge) |
| 3872 |
{ |
| 3873 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 3874 |
current_rect.x = context->indicator_target.x + (context->indicator_target.width - current_rect.width); |
| 3875 |
current_rect.y = context->indicator_target.y + (context->indicator_target.height - current_rect.height); |
| 3876 |
break; |
| 3877 |
case GDK_WINDOW_EDGE_NORTH: |
| 3878 |
current_rect.y = context->indicator_target.y + (context->indicator_target.height - current_rect.height); |
| 3879 |
break; |
| 3880 |
case GDK_WINDOW_EDGE_WEST: |
| 3881 |
current_rect.x = context->indicator_target.x + (context->indicator_target.width - current_rect.width); |
| 3882 |
break; |
| 3883 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 3884 |
current_rect.x = context->indicator_target.x + (context->indicator_target.width - current_rect.width); |
| 3885 |
current_rect.y = context->indicator_target.y; |
| 3886 |
break; |
| 3887 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 3888 |
current_rect.x = context->indicator_target.x; |
| 3889 |
current_rect.y = context->indicator_target.y + (context->indicator_target.height - current_rect.height); |
| 3890 |
break; |
| 3891 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 3892 |
current_rect.x = context->indicator_target.x; |
| 3893 |
current_rect.y = context->indicator_target.y; |
| 3894 |
break; |
| 3895 |
case GDK_WINDOW_EDGE_SOUTH: |
| 3896 |
current_rect.y = context->indicator_target.y; |
| 3897 |
break; |
| 3898 |
case GDK_WINDOW_EDGE_EAST: |
| 3899 |
current_rect.x = context->indicator_target.x; |
| 3900 |
break; |
| 3901 |
} |
| 3902 |
} |
| 3903 |
|
| 3904 |
cr = cairo_create (context->indicator_surface); |
| 3905 |
rounded_rectangle (cr, |
| 3906 |
(current_rect.x - context->indicator_window_rect.x) * impl->window_scale, |
| 3907 |
(current_rect.y - context->indicator_window_rect.y) * impl->window_scale, |
| 3908 |
current_rect.width * impl->window_scale, |
| 3909 |
current_rect.height * impl->window_scale, |
| 3910 |
corner_radius, |
| 3911 |
line_width, |
| 3912 |
&fill, &outline); |
| 3913 |
cairo_destroy (cr); |
| 3914 |
|
| 3915 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3916 |
GDK_NOTE (MISC, g_print ("Indicator is %d x %d @ %d : %d; current time is %" G_GINT64_FORMAT "\n", |
| 3917 |
current_rect.width, current_rect.height, |
| 3918 |
current_rect.x - context->indicator_window_rect.x, |
| 3919 |
current_rect.y - context->indicator_window_rect.y, |
| 3920 |
current_time)); |
| 3921 |
#endif |
| 3922 |
|
| 3923 |
return last_draw; |
| 3924 |
} |
| 3925 |
|
| 3926 |
static gboolean |
| 3927 |
redraw_indicator (gpointer user_data) |
| 3928 |
{ |
| 3929 |
GdkW32DragMoveResizeContext *context = user_data; |
| 3930 |
POINT window_position; |
| 3931 |
SIZE window_size; |
| 3932 |
BLENDFUNCTION blender; |
| 3933 |
HDC hdc; |
| 3934 |
POINT source_point = { 0, 0 }; |
| 3935 |
gboolean last_draw; |
| 3936 |
gdouble indicator_opacity; |
| 3937 |
GdkWindowImplWin32 *impl; |
| 3938 |
gboolean do_source_remove = FALSE; |
| 3939 |
|
| 3940 |
indicator_opacity = AEROSNAP_INDICATOR_OPACITY; |
| 3941 |
|
| 3942 |
if (GDK_WINDOW_DESTROYED (context->window) || |
| 3943 |
!ensure_snap_indicator_exists (context)) |
| 3944 |
{ |
| 3945 |
do_source_remove = TRUE; |
| 3946 |
} |
| 3947 |
|
| 3948 |
impl = GDK_WINDOW_IMPL_WIN32 (context->window->impl); |
| 3949 |
|
| 3950 |
if (!ensure_snap_indicator_surface (context, |
| 3951 |
context->indicator_window_rect.width, |
| 3952 |
context->indicator_window_rect.height, |
| 3953 |
impl->window_scale)) |
| 3954 |
{ |
| 3955 |
do_source_remove = TRUE; |
| 3956 |
} |
| 3957 |
|
| 3958 |
if (do_source_remove) |
| 3959 |
{ |
| 3960 |
context->timer = 0; |
| 3961 |
return G_SOURCE_REMOVE; |
| 3962 |
} |
| 3963 |
|
| 3964 |
last_draw = draw_indicator (context, context->draw_timestamp); |
| 3965 |
|
| 3966 |
window_position.x = context->indicator_window_rect.x * impl->window_scale - _gdk_offset_x; |
| 3967 |
window_position.y = context->indicator_window_rect.y * impl->window_scale - _gdk_offset_y; |
| 3968 |
window_size.cx = context->indicator_window_rect.width * impl->window_scale; |
| 3969 |
window_size.cy = context->indicator_window_rect.height * impl->window_scale; |
| 3970 |
|
| 3971 |
blender.BlendOp = AC_SRC_OVER; |
| 3972 |
blender.BlendFlags = 0; |
| 3973 |
blender.AlphaFormat = AC_SRC_ALPHA; |
| 3974 |
blender.SourceConstantAlpha = 255 * indicator_opacity; |
| 3975 |
|
| 3976 |
hdc = cairo_win32_surface_get_dc (context->indicator_surface); |
| 3977 |
|
| 3978 |
API_CALL (SetWindowPos, (context->shape_indicator, |
| 3979 |
GDK_WINDOW_HWND (context->window), |
| 3980 |
0, 0, 0, 0, |
| 3981 |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_NOACTIVATE)); |
| 3982 |
|
| 3983 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 3984 |
GDK_NOTE (MISC, g_print ("Indicator window position is %ld x %ld @ %ld : %ld\n", |
| 3985 |
window_size.cx, window_size.cy, |
| 3986 |
window_position.x, window_position.y)); |
| 3987 |
#endif |
| 3988 |
|
| 3989 |
API_CALL (UpdateLayeredWindow, (context->shape_indicator, NULL, |
| 3990 |
&window_position, &window_size, |
| 3991 |
hdc, &source_point, |
| 3992 |
0, &blender, ULW_ALPHA)); |
| 3993 |
|
| 3994 |
if (last_draw) |
| 3995 |
context->timer = 0; |
| 3996 |
|
| 3997 |
return last_draw ? G_SOURCE_REMOVE : G_SOURCE_CONTINUE; |
| 3998 |
} |
| 3999 |
|
| 4000 |
static GdkRectangle |
| 4001 |
unity_of_rects (GdkRectangle a, |
| 4002 |
GdkRectangle b) |
| 4003 |
{ |
| 4004 |
GdkRectangle u = b; |
| 4005 |
|
| 4006 |
if (a.x < u.x) |
| 4007 |
{ |
| 4008 |
u.width += u.x - a.x; |
| 4009 |
u.x = a.x; |
| 4010 |
} |
| 4011 |
|
| 4012 |
if (a.y < u.y) |
| 4013 |
{ |
| 4014 |
u.height += (u.y - a.y); |
| 4015 |
u.y = a.y; |
| 4016 |
} |
| 4017 |
|
| 4018 |
if (a.x + a.width > u.x + u.width) |
| 4019 |
u.width += (a.x + a.width) - (u.x + u.width); |
| 4020 |
|
| 4021 |
if (a.y + a.height > u.y + u.height) |
| 4022 |
u.height += (a.y + a.height) - (u.y + u.height); |
| 4023 |
|
| 4024 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 4025 |
GDK_NOTE (MISC, g_print ("Unified 2 rects into %d x %d @ %d : %d\n", |
| 4026 |
u.width, u.height, u.x, u.y)); |
| 4027 |
#endif |
| 4028 |
|
| 4029 |
return u; |
| 4030 |
} |
| 4031 |
|
| 4032 |
static void |
| 4033 |
start_indicator_drawing (GdkW32DragMoveResizeContext *context, |
| 4034 |
GdkRectangle from, |
| 4035 |
GdkRectangle to, |
| 4036 |
guint scale) |
| 4037 |
{ |
| 4038 |
GdkRectangle to_adjusted, from_adjusted, from_or_to; |
| 4039 |
gint64 indicator_animation_tick = AEROSNAP_INDICATOR_ANIMATION_TICK; |
| 4040 |
|
| 4041 |
GDK_NOTE (MISC, g_print ("Start drawing snap indicator %d x %d @ %d : %d -> %d x %d @ %d : %d\n", |
| 4042 |
from.width * scale, from.height * scale, from.x, from.y, to.width * scale, to.height * scale, to.x, to.y)); |
| 4043 |
|
| 4044 |
if (GDK_WINDOW_DESTROYED (context->window)) |
| 4045 |
return; |
| 4046 |
|
| 4047 |
if (!ensure_snap_indicator_exists (context)) |
| 4048 |
return; |
| 4049 |
|
| 4050 |
from_or_to = unity_of_rects (from, to); |
| 4051 |
|
| 4052 |
if (!ensure_snap_indicator_surface (context, from_or_to.width, from_or_to.height, scale)) |
| 4053 |
return; |
| 4054 |
|
| 4055 |
to_adjusted = to; |
| 4056 |
adjust_indicator_rectangle (&to_adjusted, TRUE); |
| 4057 |
|
| 4058 |
from_adjusted = from; |
| 4059 |
adjust_indicator_rectangle (&from_adjusted, TRUE); |
| 4060 |
|
| 4061 |
context->draw_timestamp = 0; |
| 4062 |
context->indicator_start = from_adjusted; |
| 4063 |
context->indicator_target = to_adjusted; |
| 4064 |
context->indicator_window_rect = from_or_to; |
| 4065 |
context->indicator_start_time = g_get_monotonic_time (); |
| 4066 |
|
| 4067 |
if (context->timer) |
| 4068 |
{ |
| 4069 |
g_source_remove (context->timer); |
| 4070 |
context->timer = 0; |
| 4071 |
} |
| 4072 |
|
| 4073 |
context->timer = g_timeout_add_full (G_PRIORITY_DEFAULT, |
| 4074 |
indicator_animation_tick, |
| 4075 |
redraw_indicator, |
| 4076 |
context, |
| 4077 |
NULL); |
| 4078 |
} |
| 4079 |
|
| 4080 |
static void |
| 4081 |
update_fullup_indicator (GdkWindow *window, |
| 4082 |
GdkW32DragMoveResizeContext *context) |
| 4083 |
{ |
| 4084 |
SHORT maxysize; |
| 4085 |
GdkRectangle from, to; |
| 4086 |
GdkRectangle to_adjusted, from_adjusted, from_or_to; |
| 4087 |
GdkWindowImplWin32 *impl; |
| 4088 |
|
| 4089 |
GDK_NOTE (MISC, g_print ("Update fullup indicator\n")); |
| 4090 |
|
| 4091 |
if (GDK_WINDOW_DESTROYED (context->window)) |
| 4092 |
return; |
| 4093 |
|
| 4094 |
if (context->shape_indicator == NULL) |
| 4095 |
return; |
| 4096 |
|
| 4097 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4098 |
maxysize = GetSystemMetrics (SM_CYVIRTUALSCREEN); |
| 4099 |
gdk_window_get_position (window, &to.x, &to.y); |
| 4100 |
to.width = gdk_window_get_width (window); |
| 4101 |
to.height = gdk_window_get_height (window); |
| 4102 |
|
| 4103 |
to.y = 0; |
| 4104 |
to.height = maxysize; |
| 4105 |
from = context->indicator_target; |
| 4106 |
|
| 4107 |
if (context->timer == 0) |
| 4108 |
{ |
| 4109 |
from_adjusted = from; |
| 4110 |
adjust_indicator_rectangle (&from_adjusted, FALSE); |
| 4111 |
|
| 4112 |
GDK_NOTE (MISC, g_print ("Restart fullup animation from %d x %d @ %d : %d -> %d x %d @ %d x %d\n", |
| 4113 |
context->indicator_target.width, context->indicator_target.height, |
| 4114 |
context->indicator_target.x, context->indicator_target.y, |
| 4115 |
to.width, to.height, to.x, to.y)); |
| 4116 |
start_indicator_drawing (context, from_adjusted, to, impl->window_scale); |
| 4117 |
|
| 4118 |
return; |
| 4119 |
} |
| 4120 |
|
| 4121 |
from_or_to = unity_of_rects (from, to); |
| 4122 |
|
| 4123 |
to_adjusted = to; |
| 4124 |
adjust_indicator_rectangle (&to_adjusted, TRUE); |
| 4125 |
|
| 4126 |
GDK_NOTE (MISC, g_print ("Retarget fullup animation %d x %d @ %d : %d -> %d x %d @ %d x %d\n", |
| 4127 |
context->indicator_target.width, context->indicator_target.height, |
| 4128 |
context->indicator_target.x, context->indicator_target.y, |
| 4129 |
to_adjusted.width, to_adjusted.height, to_adjusted.x, to_adjusted.y)); |
| 4130 |
|
| 4131 |
context->indicator_target = to_adjusted; |
| 4132 |
context->indicator_window_rect = from_or_to; |
| 4133 |
|
| 4134 |
ensure_snap_indicator_surface (context, from_or_to.width, from_or_to.height, impl->window_scale); |
| 4135 |
} |
| 4136 |
|
| 4137 |
static void |
| 4138 |
start_indicator (GdkWindow *window, |
| 4139 |
GdkW32DragMoveResizeContext *context, |
| 4140 |
gint x, |
| 4141 |
gint y, |
| 4142 |
GdkWin32AeroSnapState state) |
| 4143 |
{ |
| 4144 |
GdkScreen *screen; |
| 4145 |
gint monitor; |
| 4146 |
GdkRectangle workarea; |
| 4147 |
SHORT maxysize; |
| 4148 |
GdkRectangle start_size, end_size; |
| 4149 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4150 |
|
| 4151 |
screen = gdk_window_get_screen (window); |
| 4152 |
monitor = gdk_screen_get_monitor_at_point (screen, x, y); |
| 4153 |
gdk_screen_get_monitor_workarea (screen, monitor, &workarea); |
| 4154 |
|
| 4155 |
maxysize = GetSystemMetrics (SM_CYVIRTUALSCREEN) / impl->window_scale; |
| 4156 |
gdk_window_get_position (window, &start_size.x, &start_size.y); |
| 4157 |
start_size.width = gdk_window_get_width (window); |
| 4158 |
start_size.height = gdk_window_get_height (window); |
| 4159 |
|
| 4160 |
end_size = start_size; |
| 4161 |
|
| 4162 |
switch (state) |
| 4163 |
{ |
| 4164 |
case GDK_WIN32_AEROSNAP_STATE_UNDETERMINED: |
| 4165 |
return; |
| 4166 |
case GDK_WIN32_AEROSNAP_STATE_MAXIMIZE: |
| 4167 |
end_size.x = workarea.x; |
| 4168 |
end_size.y = workarea.y; |
| 4169 |
end_size.width = workarea.width; |
| 4170 |
end_size.height = workarea.height; |
| 4171 |
break; |
| 4172 |
case GDK_WIN32_AEROSNAP_STATE_HALFLEFT: |
| 4173 |
end_size.x = workarea.x; |
| 4174 |
end_size.y = workarea.y; |
| 4175 |
end_size.width = workarea.width / 2; |
| 4176 |
end_size.height = workarea.height; |
| 4177 |
break; |
| 4178 |
case GDK_WIN32_AEROSNAP_STATE_HALFRIGHT: |
| 4179 |
end_size.x = (workarea.x + workarea.width / 2); |
| 4180 |
end_size.y = workarea.y; |
| 4181 |
end_size.width = workarea.width / 2; |
| 4182 |
end_size.height = workarea.height; |
| 4183 |
break; |
| 4184 |
case GDK_WIN32_AEROSNAP_STATE_FULLUP: |
| 4185 |
end_size.y = 0; |
| 4186 |
end_size.height = maxysize; |
| 4187 |
break; |
| 4188 |
} |
| 4189 |
|
| 4190 |
start_indicator_drawing (context, start_size, end_size, impl->window_scale); |
| 4191 |
} |
| 4192 |
|
| 4193 |
static void |
| 4194 |
stop_indicator (GdkWindow *window, |
| 4195 |
GdkW32DragMoveResizeContext *context) |
| 4196 |
{ |
| 4197 |
GDK_NOTE (MISC, g_print ("Stop drawing snap indicator\n")); |
| 4198 |
|
| 4199 |
if (context->timer) |
| 4200 |
{ |
| 4201 |
g_source_remove (context->timer); |
| 4202 |
context->timer = 0; |
| 4203 |
} |
| 4204 |
|
| 4205 |
API_CALL (SetWindowPos, (context->shape_indicator, |
| 4206 |
SWP_NOZORDER_SPECIFIED, |
| 4207 |
0, 0, 0, 0, |
| 4208 |
SWP_NOZORDER | SWP_NOMOVE | |
| 4209 |
SWP_NOSIZE | SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_NOACTIVATE)); |
| 4210 |
} |
| 4211 |
|
| 4212 |
static gint |
| 4213 |
point_in_aerosnap_region (gint x, |
| 4214 |
gint y, |
| 4215 |
AeroSnapEdgeRegion *region) |
| 4216 |
{ |
| 4217 |
gint edge, trigger; |
| 4218 |
|
| 4219 |
edge = (x >= region->edge.x && |
| 4220 |
y >= region->edge.y && |
| 4221 |
x <= region->edge.x + region->edge.width && |
| 4222 |
y <= region->edge.y + region->edge.height) ? 1 : 0; |
| 4223 |
trigger = (x >= region->trigger.x && |
| 4224 |
y >= region->trigger.y && |
| 4225 |
x <= region->trigger.x + region->trigger.width && |
| 4226 |
y <= region->trigger.y + region->trigger.height) ? 1 : 0; |
| 4227 |
return edge + trigger; |
| 4228 |
} |
| 4229 |
|
| 4230 |
static void |
| 4231 |
handle_aerosnap_move_resize (GdkWindow *window, |
| 4232 |
GdkW32DragMoveResizeContext *context, |
| 4233 |
gint x, |
| 4234 |
gint y) |
| 4235 |
{ |
| 4236 |
gint i; |
| 4237 |
AeroSnapEdgeRegion *reg; |
| 4238 |
gint maximize = 0; |
| 4239 |
gint halfleft = 0; |
| 4240 |
gint halfright = 0; |
| 4241 |
gint fullup = 0; |
| 4242 |
gboolean fullup_edge = FALSE; |
| 4243 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4244 |
|
| 4245 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE) |
| 4246 |
switch (context->edge) |
| 4247 |
{ |
| 4248 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 4249 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 4250 |
case GDK_WINDOW_EDGE_WEST: |
| 4251 |
case GDK_WINDOW_EDGE_EAST: |
| 4252 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 4253 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 4254 |
break; |
| 4255 |
case GDK_WINDOW_EDGE_SOUTH: |
| 4256 |
case GDK_WINDOW_EDGE_NORTH: |
| 4257 |
fullup_edge = TRUE; |
| 4258 |
break; |
| 4259 |
} |
| 4260 |
|
| 4261 |
for (i = 0; i < context->maximize_regions->len && maximize == 0; i++) |
| 4262 |
{ |
| 4263 |
reg = &g_array_index (context->maximize_regions, AeroSnapEdgeRegion, i); |
| 4264 |
maximize = point_in_aerosnap_region (x, y, reg); |
| 4265 |
} |
| 4266 |
|
| 4267 |
for (i = 0; i < context->halfleft_regions->len && halfleft == 0; i++) |
| 4268 |
{ |
| 4269 |
reg = &g_array_index (context->halfleft_regions, AeroSnapEdgeRegion, i); |
| 4270 |
halfleft = point_in_aerosnap_region (x, y, reg); |
| 4271 |
} |
| 4272 |
|
| 4273 |
for (i = 0; i < context->halfright_regions->len && halfright == 0; i++) |
| 4274 |
{ |
| 4275 |
reg = &g_array_index (context->halfright_regions, AeroSnapEdgeRegion, i); |
| 4276 |
halfright = point_in_aerosnap_region (x, y, reg); |
| 4277 |
} |
| 4278 |
|
| 4279 |
for (i = 0; i < context->fullup_regions->len && fullup == 0; i++) |
| 4280 |
{ |
| 4281 |
reg = &g_array_index (context->fullup_regions, AeroSnapEdgeRegion, i); |
| 4282 |
fullup = point_in_aerosnap_region (x, y, reg); |
| 4283 |
} |
| 4284 |
|
| 4285 |
#if defined(MORE_AEROSNAP_DEBUGGING) |
| 4286 |
GDK_NOTE (MISC, g_print ("AeroSnap: point %d : %d - max: %d, left %d, right %d, up %d\n", |
| 4287 |
x, y, maximize, halfleft, halfright, fullup)); |
| 4288 |
#endif |
| 4289 |
|
| 4290 |
if (!context->revealed) |
| 4291 |
{ |
| 4292 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && maximize == 2) |
| 4293 |
{ |
| 4294 |
context->revealed = TRUE; |
| 4295 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_MAXIMIZE; |
| 4296 |
start_indicator (window, context, x, y, context->current_snap); |
| 4297 |
} |
| 4298 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && halfleft == 2) |
| 4299 |
{ |
| 4300 |
context->revealed = TRUE; |
| 4301 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFLEFT; |
| 4302 |
start_indicator (window, context, x, y, context->current_snap); |
| 4303 |
} |
| 4304 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && halfright == 2) |
| 4305 |
{ |
| 4306 |
context->revealed = TRUE; |
| 4307 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFRIGHT; |
| 4308 |
start_indicator (window, context, x, y, context->current_snap); |
| 4309 |
} |
| 4310 |
else if (context->op == GDK_WIN32_DRAGOP_RESIZE && fullup == 2 && fullup_edge) |
| 4311 |
{ |
| 4312 |
context->revealed = TRUE; |
| 4313 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_FULLUP; |
| 4314 |
start_indicator (window, context, x, y, context->current_snap); |
| 4315 |
} |
| 4316 |
|
| 4317 |
return; |
| 4318 |
} |
| 4319 |
|
| 4320 |
switch (context->current_snap) |
| 4321 |
{ |
| 4322 |
case GDK_WIN32_AEROSNAP_STATE_UNDETERMINED: |
| 4323 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE && fullup > 0) |
| 4324 |
{ |
| 4325 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_FULLUP; |
| 4326 |
start_indicator (window, context, x, y, context->current_snap); |
| 4327 |
} |
| 4328 |
break; |
| 4329 |
case GDK_WIN32_AEROSNAP_STATE_MAXIMIZE: |
| 4330 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && maximize > 0) |
| 4331 |
break; |
| 4332 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && halfleft > 0) |
| 4333 |
{ |
| 4334 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFLEFT; |
| 4335 |
start_indicator (window, context, x, y, context->current_snap); |
| 4336 |
} |
| 4337 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && halfright > 0) |
| 4338 |
{ |
| 4339 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFRIGHT; |
| 4340 |
start_indicator (window, context, x, y, context->current_snap); |
| 4341 |
} |
| 4342 |
else |
| 4343 |
{ |
| 4344 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 4345 |
stop_indicator (window, context); |
| 4346 |
context->revealed = FALSE; |
| 4347 |
} |
| 4348 |
break; |
| 4349 |
case GDK_WIN32_AEROSNAP_STATE_HALFLEFT: |
| 4350 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && halfleft > 0) |
| 4351 |
break; |
| 4352 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && maximize > 0) |
| 4353 |
{ |
| 4354 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_MAXIMIZE; |
| 4355 |
start_indicator (window, context, x, y, context->current_snap); |
| 4356 |
} |
| 4357 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && halfright > 0) |
| 4358 |
{ |
| 4359 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFRIGHT; |
| 4360 |
start_indicator (window, context, x, y, context->current_snap); |
| 4361 |
} |
| 4362 |
else |
| 4363 |
{ |
| 4364 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 4365 |
stop_indicator (window, context); |
| 4366 |
context->revealed = FALSE; |
| 4367 |
} |
| 4368 |
break; |
| 4369 |
case GDK_WIN32_AEROSNAP_STATE_HALFRIGHT: |
| 4370 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && halfright > 0) |
| 4371 |
break; |
| 4372 |
if (context->op == GDK_WIN32_DRAGOP_MOVE && maximize > 0) |
| 4373 |
{ |
| 4374 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_MAXIMIZE; |
| 4375 |
start_indicator (window, context, x, y, context->current_snap); |
| 4376 |
} |
| 4377 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && halfleft > 0) |
| 4378 |
{ |
| 4379 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_HALFLEFT; |
| 4380 |
start_indicator (window, context, x, y, context->current_snap); |
| 4381 |
} |
| 4382 |
else |
| 4383 |
{ |
| 4384 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 4385 |
stop_indicator (window, context); |
| 4386 |
context->revealed = FALSE; |
| 4387 |
} |
| 4388 |
break; |
| 4389 |
case GDK_WIN32_AEROSNAP_STATE_FULLUP: |
| 4390 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE && fullup > 0 && fullup_edge) |
| 4391 |
{ |
| 4392 |
update_fullup_indicator (window, context); |
| 4393 |
break; |
| 4394 |
} |
| 4395 |
|
| 4396 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 4397 |
stop_indicator (window, context); |
| 4398 |
break; |
| 4399 |
} |
| 4400 |
} |
| 4401 |
|
| 4402 |
|
| 4403 |
static const gchar * |
| 4404 |
get_cursor_name_from_op (GdkW32WindowDragOp op, |
| 4405 |
GdkWindowEdge edge) |
| 4406 |
{ |
| 4407 |
switch (op) |
| 4408 |
{ |
| 4409 |
case GDK_WIN32_DRAGOP_MOVE: |
| 4410 |
return "move"; |
| 4411 |
case GDK_WIN32_DRAGOP_RESIZE: |
| 4412 |
switch (edge) |
| 4413 |
{ |
| 4414 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 4415 |
return "nw-resize"; |
| 4416 |
case GDK_WINDOW_EDGE_NORTH: |
| 4417 |
return "n-resize"; |
| 4418 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 4419 |
return "ne-resize"; |
| 4420 |
case GDK_WINDOW_EDGE_WEST: |
| 4421 |
return "w-resize"; |
| 4422 |
case GDK_WINDOW_EDGE_EAST: |
| 4423 |
return "e-resize"; |
| 4424 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 4425 |
return "sw-resize"; |
| 4426 |
case GDK_WINDOW_EDGE_SOUTH: |
| 4427 |
return "s-resize"; |
| 4428 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 4429 |
return "se-resize"; |
| 4430 |
} |
| 4431 |
/* default: warn about unhandled enum values, |
| 4432 |
* fallthrough to GDK_WIN32_DRAGOP_NONE case |
| 4433 |
*/ |
| 4434 |
case GDK_WIN32_DRAGOP_COUNT: |
| 4435 |
g_assert_not_reached (); |
| 4436 |
case GDK_WIN32_DRAGOP_NONE: |
| 4437 |
return "default"; |
| 4438 |
/* default: warn about unhandled enum values */ |
| 4439 |
} |
| 4440 |
|
| 4441 |
g_assert_not_reached (); |
| 4442 |
|
| 4443 |
return NULL; |
| 4444 |
} |
| 4445 |
|
| 4446 |
static gboolean |
| 4447 |
point_in_window (GdkWindow *window, |
| 4448 |
gdouble x, |
| 4449 |
gdouble y) |
| 4450 |
{ |
| 4451 |
return x >= 0 && x < window->width && |
| 4452 |
y >= 0 && y < window->height && |
| 4453 |
(window->shape == NULL || |
| 4454 |
cairo_region_contains_point (window->shape, x, y)) && |
| 4455 |
(window->input_shape == NULL || |
| 4456 |
cairo_region_contains_point (window->input_shape, x, y)); |
| 4457 |
} |
| 4458 |
|
| 4459 |
static GdkWindow * |
| 4460 |
child_window_at_coordinates (GdkWindow *window, |
| 4461 |
gint root_x, |
| 4462 |
gint root_y) |
| 4463 |
{ |
| 4464 |
gint x, y; |
| 4465 |
GList *l; |
| 4466 |
GList *children; |
| 4467 |
|
| 4468 |
children = gdk_window_peek_children (window); |
| 4469 |
gdk_window_get_root_origin (window, &x, &y); |
| 4470 |
x = root_x - x; |
| 4471 |
y = root_y - y; |
| 4472 |
|
| 4473 |
for (l = children; l; l = g_list_next (l)) |
| 4474 |
{ |
| 4475 |
GdkWindow *child = GDK_WINDOW (l->data); |
| 4476 |
|
| 4477 |
if (point_in_window (child, x, y)) |
| 4478 |
return child; |
| 4479 |
} |
| 4480 |
|
| 4481 |
return window; |
| 4482 |
} |
| 4483 |
|
| 4484 |
static void |
| 4485 |
setup_drag_move_resize_context (GdkWindow *window, |
| 4486 |
GdkW32DragMoveResizeContext *context, |
| 4487 |
GdkW32WindowDragOp op, |
| 4488 |
GdkWindowEdge edge, |
| 4489 |
GdkDevice *device, |
| 4490 |
gint button, |
| 4491 |
gint root_x, |
| 4492 |
gint root_y, |
| 4493 |
guint32 timestamp) |
| 4494 |
{ |
| 4495 |
RECT rect; |
| 4496 |
const gchar *cursor_name; |
| 4497 |
GdkWindow *pointer_window; |
| 4498 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4499 |
GdkDisplay *display = gdk_device_get_display (device); |
| 4500 |
gboolean maximized = gdk_window_get_state (window) & GDK_WINDOW_STATE_MAXIMIZED; |
| 4501 |
|
| 4502 |
/* Before we drag, we need to undo any maximization or snapping. |
| 4503 |
* AeroSnap behaviour: |
| 4504 |
* If snapped halfleft/halfright: |
| 4505 |
* horizontal resize: |
| 4506 |
* resize |
| 4507 |
* don't unsnap |
| 4508 |
* keep stashed unsnapped size intact |
| 4509 |
* vertical resize: |
| 4510 |
* resize |
| 4511 |
* unsnap to new size (merge cached unsnapped state with current |
| 4512 |
* snapped state in such a way that the gripped edge |
| 4513 |
* does not move) |
| 4514 |
* diagonal resize: |
| 4515 |
* difficult to test (first move is usually either purely |
| 4516 |
* horizontal or purely vertical, in which |
| 4517 |
* case the above behaviour applies) |
| 4518 |
* If snapped up: |
| 4519 |
* horizontal resize: |
| 4520 |
* resize |
| 4521 |
* don't unsnap |
| 4522 |
* apply new width and x position to unsnapped cache, |
| 4523 |
* so that unsnapped window only regains its height |
| 4524 |
* and y position, but inherits x and width from |
| 4525 |
* the fullup snapped state |
| 4526 |
* vertical resize: |
| 4527 |
* unsnap to new size (merge cached unsnapped state with current |
| 4528 |
* snapped state in such a way that the gripped edge |
| 4529 |
* does not move) |
| 4530 |
* |
| 4531 |
* This implementation behaviour: |
| 4532 |
* If snapped halfleft/halfright/fullup: |
| 4533 |
* any resize: |
| 4534 |
* unsnap to current size, discard cached pre-snap state |
| 4535 |
* |
| 4536 |
* TODO: make this implementation behave as AeroSnap on resizes? |
| 4537 |
* There's also the case where |
| 4538 |
* a halfleft/halfright window isn't unsnapped when it's |
| 4539 |
* being moved horizontally, but it's more difficult to implement. |
| 4540 |
*/ |
| 4541 |
if (op == GDK_WIN32_DRAGOP_RESIZE && |
| 4542 |
(impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFRIGHT || |
| 4543 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFLEFT || |
| 4544 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_FULLUP)) |
| 4545 |
{ |
| 4546 |
discard_snapinfo (window); |
| 4547 |
} |
| 4548 |
else if (maximized || |
| 4549 |
(impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFRIGHT || |
| 4550 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_HALFLEFT || |
| 4551 |
impl->snap_state == GDK_WIN32_AEROSNAP_STATE_FULLUP)) |
| 4552 |
{ |
| 4553 |
GdkScreen *screen; |
| 4554 |
gint monitor; |
| 4555 |
gint wx, wy, wwidth, wheight; |
| 4556 |
gint swx, swy, swwidth, swheight; |
| 4557 |
gboolean pointer_outside_of_window; |
| 4558 |
gint offsetx, offsety; |
| 4559 |
gboolean left_half; |
| 4560 |
|
| 4561 |
screen = gdk_display_get_default_screen (gdk_window_get_display (window)); |
| 4562 |
monitor = gdk_screen_get_monitor_at_window (screen, window); |
| 4563 |
gdk_window_get_geometry (window, &wx, &wy, &wwidth, &wheight); |
| 4564 |
|
| 4565 |
swx = wx; |
| 4566 |
swy = wy; |
| 4567 |
swwidth = wwidth; |
| 4568 |
swheight = wheight; |
| 4569 |
|
| 4570 |
/* Subtract window shadow. We don't want pointer to go outside of |
| 4571 |
* the visible window during drag-move. For drag-resize it's OK. |
| 4572 |
* Don't take shadow into account if the window is maximized - |
| 4573 |
* maximized windows don't have shadows. |
| 4574 |
*/ |
| 4575 |
if (op == GDK_WIN32_DRAGOP_MOVE && !maximized) |
| 4576 |
{ |
| 4577 |
swx += impl->margins.left / impl->window_scale; |
| 4578 |
swy += impl->margins.top / impl->window_scale; |
| 4579 |
swwidth -= impl->margins_x; |
| 4580 |
swheight -= impl->margins_y; |
| 4581 |
} |
| 4582 |
|
| 4583 |
pointer_outside_of_window = root_x < swx || root_x > swx + swwidth || |
| 4584 |
root_y < swy || root_y > swy + swheight; |
| 4585 |
/* Calculate the offset of the pointer relative to the window */ |
| 4586 |
offsetx = root_x - swx; |
| 4587 |
offsety = root_y - swy; |
| 4588 |
|
| 4589 |
/* Figure out in which half of the window the pointer is. |
| 4590 |
* The code currently only concerns itself with horizontal |
| 4591 |
* dimension (left/right halves). |
| 4592 |
* There's no upper/lower half, because usually window |
| 4593 |
* is dragged by its upper half anyway. If that changes, adjust |
| 4594 |
* accordingly. |
| 4595 |
*/ |
| 4596 |
left_half = (offsetx < swwidth / 2); |
| 4597 |
|
| 4598 |
/* Inverse the offset for it to be from the right edge */ |
| 4599 |
if (!left_half) |
| 4600 |
offsetx = swwidth - offsetx; |
| 4601 |
|
| 4602 |
GDK_NOTE (MISC, g_print ("Pointer at %d : %d, this is %d : %d relative to the window's %s\n", |
| 4603 |
root_x, root_y, offsetx, offsety, |
| 4604 |
left_half ? "left half" : "right half")); |
| 4605 |
|
| 4606 |
/* Move window in such a way that on unmaximization/unsnapping the pointer |
| 4607 |
* is still pointing at the appropriate half of the window, |
| 4608 |
* with the same offset from the left or right edge. If the new |
| 4609 |
* window size is too small, and adding that offset puts the pointer |
| 4610 |
* into the other half or even beyond, move the pointer to the middle. |
| 4611 |
*/ |
| 4612 |
if (!pointer_outside_of_window && maximized) |
| 4613 |
{ |
| 4614 |
WINDOWPLACEMENT placement; |
| 4615 |
gint unmax_width, unmax_height; |
| 4616 |
gint shadow_unmax_width, shadow_unmax_height; |
| 4617 |
|
| 4618 |
placement.length = sizeof (placement); |
| 4619 |
API_CALL (GetWindowPlacement, (GDK_WINDOW_HWND (window), &placement)); |
| 4620 |
|
| 4621 |
GDK_NOTE (MISC, g_print ("W32 WM unmaximized window placement is %ld x %ld @ %ld : %ld\n", |
| 4622 |
placement.rcNormalPosition.right - placement.rcNormalPosition.left, |
| 4623 |
placement.rcNormalPosition.bottom - placement.rcNormalPosition.top, |
| 4624 |
placement.rcNormalPosition.left + _gdk_offset_x, |
| 4625 |
placement.rcNormalPosition.top + _gdk_offset_y)); |
| 4626 |
|
| 4627 |
unmax_width = placement.rcNormalPosition.right - placement.rcNormalPosition.left; |
| 4628 |
unmax_height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top; |
| 4629 |
|
| 4630 |
shadow_unmax_width = unmax_width - impl->margins_x * impl->window_scale; |
| 4631 |
shadow_unmax_height = unmax_height - impl->margins_y * impl->window_scale; |
| 4632 |
|
| 4633 |
if (offsetx * impl->window_scale < (shadow_unmax_width / 2) && |
| 4634 |
offsety * impl->window_scale < (shadow_unmax_height / 2)) |
| 4635 |
{ |
| 4636 |
placement.rcNormalPosition.top = (root_y - offsety + impl->margins.top) * impl->window_scale - _gdk_offset_y; |
| 4637 |
placement.rcNormalPosition.bottom = placement.rcNormalPosition.top + unmax_height; |
| 4638 |
|
| 4639 |
if (left_half) |
| 4640 |
{ |
| 4641 |
placement.rcNormalPosition.left = (root_x - offsetx + impl->margins.left) * impl->window_scale - _gdk_offset_x; |
| 4642 |
placement.rcNormalPosition.right = placement.rcNormalPosition.left + unmax_width; |
| 4643 |
} |
| 4644 |
else |
| 4645 |
{ |
| 4646 |
placement.rcNormalPosition.right = (root_x + offsetx + impl->margins.right) * impl->window_scale - _gdk_offset_x; |
| 4647 |
placement.rcNormalPosition.left = placement.rcNormalPosition.right - unmax_width; |
| 4648 |
} |
| 4649 |
} |
| 4650 |
else |
| 4651 |
{ |
| 4652 |
placement.rcNormalPosition.left = (root_x * impl->window_scale) - |
| 4653 |
(unmax_width / 2) - |
| 4654 |
_gdk_offset_x; |
| 4655 |
|
| 4656 |
if (offsety * impl->window_scale < shadow_unmax_height / 2) |
| 4657 |
placement.rcNormalPosition.top = (root_y - offsety + impl->margins.top) * impl->window_scale - _gdk_offset_y; |
| 4658 |
else |
| 4659 |
placement.rcNormalPosition.top = (root_y * impl->window_scale) - |
| 4660 |
(unmax_height / 2) - |
| 4661 |
_gdk_offset_y; |
| 4662 |
|
| 4663 |
placement.rcNormalPosition.right = placement.rcNormalPosition.left + unmax_width; |
| 4664 |
placement.rcNormalPosition.bottom = placement.rcNormalPosition.top + unmax_height; |
| 4665 |
} |
| 4666 |
|
| 4667 |
GDK_NOTE (MISC, g_print ("Unmaximized window will be at %ld : %ld\n", |
| 4668 |
placement.rcNormalPosition.left + _gdk_offset_x, |
| 4669 |
placement.rcNormalPosition.top + _gdk_offset_y)); |
| 4670 |
|
| 4671 |
API_CALL (SetWindowPlacement, (GDK_WINDOW_HWND (window), &placement)); |
| 4672 |
} |
| 4673 |
else if (!pointer_outside_of_window && impl->snap_stash_int) |
| 4674 |
{ |
| 4675 |
GdkRectangle new_pos; |
| 4676 |
GdkRectangle snew_pos; |
| 4677 |
|
| 4678 |
new_pos.width = impl->snap_stash_int->width; |
| 4679 |
new_pos.height = impl->snap_stash_int->height; |
| 4680 |
snew_pos = new_pos; |
| 4681 |
|
| 4682 |
if (op == GDK_WIN32_DRAGOP_MOVE) |
| 4683 |
{ |
| 4684 |
snew_pos.width -= impl->margins_x; |
| 4685 |
snew_pos.height -= impl->margins_y; |
| 4686 |
} |
| 4687 |
|
| 4688 |
if (offsetx < snew_pos.width / 2 && offsety < snew_pos.height / 2) |
| 4689 |
{ |
| 4690 |
new_pos.y = root_y - offsety + impl->margins.top / impl->window_scale; |
| 4691 |
|
| 4692 |
if (left_half) |
| 4693 |
new_pos.x = root_x - offsetx + impl->margins.left / impl->window_scale; |
| 4694 |
else |
| 4695 |
new_pos.x = root_x + offsetx + impl->margins.left / impl->window_scale - new_pos.width; |
| 4696 |
} |
| 4697 |
else |
| 4698 |
{ |
| 4699 |
new_pos.x = root_x - new_pos.width / 2; |
| 4700 |
new_pos.y = root_y - new_pos.height / 2; |
| 4701 |
} |
| 4702 |
|
| 4703 |
GDK_NOTE (MISC, g_print ("Unsnapped window to %d : %d\n", |
| 4704 |
new_pos.x, new_pos.y)); |
| 4705 |
discard_snapinfo (window); |
| 4706 |
gdk_window_move_resize (window, new_pos.x, new_pos.y, |
| 4707 |
new_pos.width, new_pos.height); |
| 4708 |
} |
| 4709 |
|
| 4710 |
|
| 4711 |
if (maximized) |
| 4712 |
gdk_window_unmaximize (window); |
| 4713 |
else |
| 4714 |
unsnap (window, screen, monitor); |
| 4715 |
|
| 4716 |
if (pointer_outside_of_window) |
| 4717 |
{ |
| 4718 |
/* Pointer outside of the window, move pointer into window */ |
| 4719 |
GDK_NOTE (MISC, g_print ("Pointer at %d : %d is outside of %d x %d @ %d : %d, move it to %d : %d\n", |
| 4720 |
root_x, root_y, wwidth, wheight, wx, wy, wx + wwidth / 2, wy + wheight / 2)); |
| 4721 |
root_x = wx + wwidth / 2; |
| 4722 |
/* This is Gnome behaviour. Windows WM would put the pointer |
| 4723 |
* in the middle of the titlebar, but GDK doesn't know where |
| 4724 |
* the titlebar is, if any. |
| 4725 |
*/ |
| 4726 |
root_y = wy + wheight / 2; |
| 4727 |
gdk_device_warp (device, screen, |
| 4728 |
root_x, root_y); |
| 4729 |
} |
| 4730 |
} |
| 4731 |
|
| 4732 |
_gdk_win32_get_window_rect (window, &rect); |
| 4733 |
|
| 4734 |
cursor_name = get_cursor_name_from_op (op, edge); |
| 4735 |
|
| 4736 |
context->cursor = _gdk_win32_display_get_cursor_for_name (display, cursor_name); |
| 4737 |
|
| 4738 |
pointer_window = child_window_at_coordinates (window, root_x, root_y); |
| 4739 |
|
| 4740 |
/* Note: This triggers a WM_CAPTURECHANGED, which will trigger |
| 4741 |
* gdk_win32_window_end_move_resize_drag(), which will end |
| 4742 |
* our op before it even begins, but only if context->op is not NONE. |
| 4743 |
* This is why we first do the grab, *then* set the op. |
| 4744 |
*/ |
| 4745 |
gdk_device_grab (device, pointer_window, |
| 4746 |
GDK_OWNERSHIP_NONE, FALSE, |
| 4747 |
GDK_ALL_EVENTS_MASK, |
| 4748 |
context->cursor, |
| 4749 |
timestamp); |
| 4750 |
|
| 4751 |
context->window = g_object_ref (window); |
| 4752 |
context->op = op; |
| 4753 |
context->edge = edge; |
| 4754 |
context->device = device; |
| 4755 |
context->button = button; |
| 4756 |
context->start_root_x = root_x; |
| 4757 |
context->start_root_y = root_y; |
| 4758 |
context->timestamp = timestamp; |
| 4759 |
context->start_rect = rect; |
| 4760 |
|
| 4761 |
context->shape_indicator = NULL; |
| 4762 |
context->revealed = FALSE; |
| 4763 |
context->halfleft_regions = g_array_new (FALSE, FALSE, sizeof (AeroSnapEdgeRegion)); |
| 4764 |
context->halfright_regions = g_array_new (FALSE, FALSE, sizeof (AeroSnapEdgeRegion)); |
| 4765 |
context->maximize_regions = g_array_new (FALSE, FALSE, sizeof (AeroSnapEdgeRegion)); |
| 4766 |
context->fullup_regions = g_array_new (FALSE, FALSE, sizeof (AeroSnapEdgeRegion)); |
| 4767 |
|
| 4768 |
calculate_aerosnap_regions (context); |
| 4769 |
|
| 4770 |
GDK_NOTE (EVENTS, |
| 4771 |
g_print ("begin drag moveresize: window %p, toplevel %p, " |
| 4772 |
"op %u, edge %d, device %p, " |
| 4773 |
"button %d, coord %d:%d, time %u\n", |
| 4774 |
pointer_window, gdk_window_get_toplevel (window), |
| 4775 |
context->op, context->edge, context->device, |
| 4776 |
context->button, context->start_root_x, |
| 4777 |
context->start_root_y, context->timestamp)); |
| 4778 |
} |
| 4779 |
|
| 4780 |
void |
| 4781 |
gdk_win32_window_end_move_resize_drag (GdkWindow *window) |
| 4782 |
{ |
| 4783 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4784 |
GdkW32DragMoveResizeContext *context = &impl->drag_move_resize_context; |
| 4785 |
|
| 4786 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE) |
| 4787 |
gdk_win32_window_invalidate_egl_framebuffer (window); |
| 4788 |
|
| 4789 |
context->op = GDK_WIN32_DRAGOP_NONE; |
| 4790 |
|
| 4791 |
gdk_device_ungrab (context->device, GDK_CURRENT_TIME); |
| 4792 |
|
| 4793 |
g_clear_object (&context->cursor); |
| 4794 |
|
| 4795 |
context->revealed = FALSE; |
| 4796 |
|
| 4797 |
if (context->timer) |
| 4798 |
{ |
| 4799 |
g_source_remove (context->timer); |
| 4800 |
context->timer = 0; |
| 4801 |
} |
| 4802 |
|
| 4803 |
g_clear_object (&context->window); |
| 4804 |
|
| 4805 |
if (context->indicator_surface) |
| 4806 |
{ |
| 4807 |
cairo_surface_destroy (context->indicator_surface); |
| 4808 |
context->indicator_surface = NULL; |
| 4809 |
} |
| 4810 |
|
| 4811 |
if (context->shape_indicator) |
| 4812 |
{ |
| 4813 |
stop_indicator (window, context); |
| 4814 |
DestroyWindow (context->shape_indicator); |
| 4815 |
context->shape_indicator = NULL; |
| 4816 |
} |
| 4817 |
|
| 4818 |
g_clear_pointer (&context->halfleft_regions, g_array_unref); |
| 4819 |
g_clear_pointer (&context->halfright_regions, g_array_unref); |
| 4820 |
g_clear_pointer (&context->maximize_regions, g_array_unref); |
| 4821 |
g_clear_pointer (&context->fullup_regions, g_array_unref); |
| 4822 |
|
| 4823 |
GDK_NOTE (EVENTS, |
| 4824 |
g_print ("end drag moveresize: window %p, toplevel %p," |
| 4825 |
"op %u, edge %d, device %p, " |
| 4826 |
"button %d, coord %d:%d, time %u\n", |
| 4827 |
window, gdk_window_get_toplevel (window), |
| 4828 |
context->op, context->edge, context->device, |
| 4829 |
context->button, context->start_root_x, |
| 4830 |
context->start_root_y, context->timestamp)); |
| 4831 |
|
| 4832 |
if (context->current_snap != GDK_WIN32_AEROSNAP_STATE_UNDETERMINED) |
| 4833 |
apply_snap (window, context->current_snap); |
| 4834 |
|
| 4835 |
context->current_snap = GDK_WIN32_AEROSNAP_STATE_UNDETERMINED; |
| 4836 |
} |
| 4837 |
|
| 4838 |
static void |
| 4839 |
gdk_win32_get_window_size_and_position_from_client_rect (GdkWindow *window, |
| 4840 |
RECT *window_rect, |
| 4841 |
SIZE *window_size, |
| 4842 |
POINT *window_position) |
| 4843 |
{ |
| 4844 |
GdkWindowImplWin32 *impl; |
| 4845 |
|
| 4846 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4847 |
|
| 4848 |
/* Turn client area into window area */ |
| 4849 |
_gdk_win32_adjust_client_rect (window, window_rect); |
| 4850 |
|
| 4851 |
/* Convert GDK screen coordinates to W32 desktop coordinates */ |
| 4852 |
window_rect->left -= _gdk_offset_x; |
| 4853 |
window_rect->right -= _gdk_offset_x; |
| 4854 |
window_rect->top -= _gdk_offset_y; |
| 4855 |
window_rect->bottom -= _gdk_offset_y; |
| 4856 |
|
| 4857 |
window_position->x = window_rect->left; |
| 4858 |
window_position->y = window_rect->top; |
| 4859 |
window_size->cx = window_rect->right - window_rect->left; |
| 4860 |
window_size->cy = window_rect->bottom - window_rect->top; |
| 4861 |
} |
| 4862 |
|
| 4863 |
static void |
| 4864 |
gdk_win32_update_layered_window_from_cache (GdkWindow *window, |
| 4865 |
RECT *client_rect) |
| 4866 |
{ |
| 4867 |
POINT window_position; |
| 4868 |
SIZE window_size; |
| 4869 |
BLENDFUNCTION blender; |
| 4870 |
HDC hdc; |
| 4871 |
SIZE *window_size_ptr; |
| 4872 |
POINT source_point = { 0, 0 }; |
| 4873 |
POINT *source_point_ptr; |
| 4874 |
GdkWindowImplWin32 *impl; |
| 4875 |
|
| 4876 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4877 |
|
| 4878 |
gdk_win32_get_window_size_and_position_from_client_rect (window, |
| 4879 |
client_rect, |
| 4880 |
&window_size, |
| 4881 |
&window_position); |
| 4882 |
|
| 4883 |
blender.BlendOp = AC_SRC_OVER; |
| 4884 |
blender.BlendFlags = 0; |
| 4885 |
blender.AlphaFormat = AC_SRC_ALPHA; |
| 4886 |
blender.SourceConstantAlpha = impl->layered_opacity * 255; |
| 4887 |
|
| 4888 |
/* Size didn't change, so move immediately, no need to wait for redraw */ |
| 4889 |
/* Strictly speaking, we don't need to supply hdc, source_point and |
| 4890 |
* window_size here. However, without these arguments |
| 4891 |
* the window moves but does not update its contents on Windows 7 when |
| 4892 |
* desktop composition is off. This forces us to provide hdc and |
| 4893 |
* source_point. window_size is here to avoid the function |
| 4894 |
* inexplicably failing with error 317. |
| 4895 |
*/ |
| 4896 |
if (gdk_screen_is_composited (gdk_window_get_screen (window))) |
| 4897 |
{ |
| 4898 |
hdc = NULL; |
| 4899 |
window_size_ptr = NULL; |
| 4900 |
source_point_ptr = NULL; |
| 4901 |
} |
| 4902 |
else |
| 4903 |
{ |
| 4904 |
hdc = cairo_win32_surface_get_dc (impl->cache_surface); |
| 4905 |
window_size_ptr = &window_size; |
| 4906 |
source_point_ptr = &source_point; |
| 4907 |
} |
| 4908 |
|
| 4909 |
API_CALL (UpdateLayeredWindow, (GDK_WINDOW_HWND (window), NULL, |
| 4910 |
&window_position, window_size_ptr, |
| 4911 |
hdc, source_point_ptr, |
| 4912 |
0, &blender, ULW_ALPHA)); |
| 4913 |
} |
| 4914 |
|
| 4915 |
void |
| 4916 |
gdk_win32_window_do_move_resize_drag (GdkWindow *window, |
| 4917 |
gint x, |
| 4918 |
gint y) |
| 4919 |
{ |
| 4920 |
RECT rect; |
| 4921 |
RECT new_rect; |
| 4922 |
gint diffy, diffx; |
| 4923 |
MINMAXINFO mmi; |
| 4924 |
GdkWindowImplWin32 *impl; |
| 4925 |
GdkW32DragMoveResizeContext *context; |
| 4926 |
gint width; |
| 4927 |
gint height; |
| 4928 |
|
| 4929 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 4930 |
context = &impl->drag_move_resize_context; |
| 4931 |
|
| 4932 |
if (!_gdk_win32_get_window_rect (window, &rect)) |
| 4933 |
return; |
| 4934 |
|
| 4935 |
new_rect = context->start_rect; |
| 4936 |
diffx = (x - context->start_root_x) * impl->window_scale; |
| 4937 |
diffy = (y - context->start_root_y) * impl->window_scale; |
| 4938 |
|
| 4939 |
switch (context->op) |
| 4940 |
{ |
| 4941 |
case GDK_WIN32_DRAGOP_RESIZE: |
| 4942 |
|
| 4943 |
switch (context->edge) |
| 4944 |
{ |
| 4945 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 4946 |
new_rect.left += diffx; |
| 4947 |
new_rect.top += diffy; |
| 4948 |
break; |
| 4949 |
|
| 4950 |
case GDK_WINDOW_EDGE_NORTH: |
| 4951 |
new_rect.top += diffy; |
| 4952 |
break; |
| 4953 |
|
| 4954 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 4955 |
new_rect.right += diffx; |
| 4956 |
new_rect.top += diffy; |
| 4957 |
break; |
| 4958 |
|
| 4959 |
case GDK_WINDOW_EDGE_WEST: |
| 4960 |
new_rect.left += diffx; |
| 4961 |
break; |
| 4962 |
|
| 4963 |
case GDK_WINDOW_EDGE_EAST: |
| 4964 |
new_rect.right += diffx; |
| 4965 |
break; |
| 4966 |
|
| 4967 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 4968 |
new_rect.left += diffx; |
| 4969 |
new_rect.bottom += diffy; |
| 4970 |
break; |
| 4971 |
|
| 4972 |
case GDK_WINDOW_EDGE_SOUTH: |
| 4973 |
new_rect.bottom += diffy; |
| 4974 |
break; |
| 4975 |
|
| 4976 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 4977 |
default: |
| 4978 |
new_rect.right += diffx; |
| 4979 |
new_rect.bottom += diffy; |
| 4980 |
break; |
| 4981 |
} |
| 4982 |
|
| 4983 |
/* When handling WM_GETMINMAXINFO, mmi is already populated |
| 4984 |
* by W32 WM and we apply our stuff on top of that. |
| 4985 |
* Here it isn't, so we should at least clear it. |
| 4986 |
*/ |
| 4987 |
memset (&mmi, 0, sizeof (mmi)); |
| 4988 |
|
| 4989 |
if (!_gdk_win32_window_fill_min_max_info (window, &mmi)) |
| 4990 |
break; |
| 4991 |
|
| 4992 |
width = new_rect.right - new_rect.left; |
| 4993 |
height = new_rect.bottom - new_rect.top; |
| 4994 |
|
| 4995 |
if (width > mmi.ptMaxTrackSize.x) |
| 4996 |
{ |
| 4997 |
switch (context->edge) |
| 4998 |
{ |
| 4999 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 5000 |
case GDK_WINDOW_EDGE_WEST: |
| 5001 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 5002 |
new_rect.left = new_rect.right - mmi.ptMaxTrackSize.x; |
| 5003 |
break; |
| 5004 |
|
| 5005 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 5006 |
case GDK_WINDOW_EDGE_EAST: |
| 5007 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 5008 |
default: |
| 5009 |
new_rect.right = new_rect.left + mmi.ptMaxTrackSize.x; |
| 5010 |
break; |
| 5011 |
} |
| 5012 |
} |
| 5013 |
else if (width < mmi.ptMinTrackSize.x) |
| 5014 |
{ |
| 5015 |
switch (context->edge) |
| 5016 |
{ |
| 5017 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 5018 |
case GDK_WINDOW_EDGE_WEST: |
| 5019 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 5020 |
new_rect.left = new_rect.right - mmi.ptMinTrackSize.x; |
| 5021 |
break; |
| 5022 |
|
| 5023 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 5024 |
case GDK_WINDOW_EDGE_EAST: |
| 5025 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 5026 |
default: |
| 5027 |
new_rect.right = new_rect.left + mmi.ptMinTrackSize.x; |
| 5028 |
break; |
| 5029 |
} |
| 5030 |
} |
| 5031 |
|
| 5032 |
if (height > mmi.ptMaxTrackSize.y) |
| 5033 |
{ |
| 5034 |
switch (context->edge) |
| 5035 |
{ |
| 5036 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 5037 |
case GDK_WINDOW_EDGE_NORTH: |
| 5038 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 5039 |
new_rect.top = new_rect.bottom - mmi.ptMaxTrackSize.y; |
| 5040 |
|
| 5041 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 5042 |
case GDK_WINDOW_EDGE_SOUTH: |
| 5043 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 5044 |
default: |
| 5045 |
new_rect.bottom = new_rect.top + mmi.ptMaxTrackSize.y; |
| 5046 |
break; |
| 5047 |
} |
| 5048 |
} |
| 5049 |
else if (height < mmi.ptMinTrackSize.y) |
| 5050 |
{ |
| 5051 |
switch (context->edge) |
| 5052 |
{ |
| 5053 |
case GDK_WINDOW_EDGE_NORTH_WEST: |
| 5054 |
case GDK_WINDOW_EDGE_NORTH: |
| 5055 |
case GDK_WINDOW_EDGE_NORTH_EAST: |
| 5056 |
new_rect.top = new_rect.bottom - mmi.ptMinTrackSize.y; |
| 5057 |
|
| 5058 |
case GDK_WINDOW_EDGE_SOUTH_WEST: |
| 5059 |
case GDK_WINDOW_EDGE_SOUTH: |
| 5060 |
case GDK_WINDOW_EDGE_SOUTH_EAST: |
| 5061 |
default: |
| 5062 |
new_rect.bottom = new_rect.top + mmi.ptMinTrackSize.y; |
| 5063 |
break; |
| 5064 |
} |
| 5065 |
} |
| 5066 |
|
| 5067 |
break; |
| 5068 |
case GDK_WIN32_DRAGOP_MOVE: |
| 5069 |
new_rect.left += diffx; |
| 5070 |
new_rect.top += diffy; |
| 5071 |
new_rect.right += diffx; |
| 5072 |
new_rect.bottom += diffy; |
| 5073 |
break; |
| 5074 |
default: |
| 5075 |
break; |
| 5076 |
} |
| 5077 |
|
| 5078 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE && |
| 5079 |
(rect.left != new_rect.left || |
| 5080 |
rect.right != new_rect.right || |
| 5081 |
rect.top != new_rect.top || |
| 5082 |
rect.bottom != new_rect.bottom)) |
| 5083 |
{ |
| 5084 |
context->native_move_resize_pending = TRUE; |
| 5085 |
_gdk_win32_do_emit_configure_event (window, new_rect); |
| 5086 |
} |
| 5087 |
else if (context->op == GDK_WIN32_DRAGOP_MOVE && |
| 5088 |
(rect.left != new_rect.left || |
| 5089 |
rect.top != new_rect.top)) |
| 5090 |
{ |
| 5091 |
context->native_move_resize_pending = FALSE; |
| 5092 |
|
| 5093 |
_gdk_win32_do_emit_configure_event (window, new_rect); |
| 5094 |
|
| 5095 |
if (impl->layered) |
| 5096 |
{ |
| 5097 |
gdk_win32_update_layered_window_from_cache (window, &new_rect); |
| 5098 |
} |
| 5099 |
else |
| 5100 |
{ |
| 5101 |
SIZE window_size; |
| 5102 |
POINT window_position; |
| 5103 |
|
| 5104 |
gdk_win32_get_window_size_and_position_from_client_rect (window, |
| 5105 |
&new_rect, |
| 5106 |
&window_size, |
| 5107 |
&window_position); |
| 5108 |
|
| 5109 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 5110 |
SWP_NOZORDER_SPECIFIED, |
| 5111 |
window_position.x, window_position.y, |
| 5112 |
0, 0, |
| 5113 |
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE)); |
| 5114 |
} |
| 5115 |
} |
| 5116 |
|
| 5117 |
if (context->op == GDK_WIN32_DRAGOP_RESIZE || |
| 5118 |
context->op == GDK_WIN32_DRAGOP_MOVE) |
| 5119 |
handle_aerosnap_move_resize (window, context, x, y); |
| 5120 |
} |
| 5121 |
|
| 5122 |
static void |
| 5123 |
gdk_win32_window_begin_resize_drag (GdkWindow *window, |
| 5124 |
GdkWindowEdge edge, |
| 5125 |
GdkDevice *device, |
| 5126 |
gint button, |
| 5127 |
gint root_x, |
| 5128 |
gint root_y, |
| 5129 |
guint32 timestamp) |
| 5130 |
{ |
| 5131 |
GdkWindowImplWin32 *impl; |
| 5132 |
|
| 5133 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5134 |
|
| 5135 |
if (GDK_WINDOW_DESTROYED (window) || |
| 5136 |
GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD || |
| 5137 |
IsIconic (GDK_WINDOW_HWND (window))) |
| 5138 |
return; |
| 5139 |
|
| 5140 |
/* Tell Windows to start interactively resizing the window by pretending that |
| 5141 |
* the left pointer button was clicked in the suitable edge or corner. This |
| 5142 |
* will only work if the button is down when this function is called, and |
| 5143 |
* will only work with button 1 (left), since Windows only allows window |
| 5144 |
* dragging using the left mouse button. |
| 5145 |
*/ |
| 5146 |
|
| 5147 |
if (button != 1) |
| 5148 |
return; |
| 5149 |
|
| 5150 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5151 |
|
| 5152 |
if (impl->drag_move_resize_context.op != GDK_WIN32_DRAGOP_NONE) |
| 5153 |
gdk_win32_window_end_move_resize_drag (window); |
| 5154 |
|
| 5155 |
setup_drag_move_resize_context (window, &impl->drag_move_resize_context, |
| 5156 |
GDK_WIN32_DRAGOP_RESIZE, edge, device, |
| 5157 |
button, root_x, root_y, timestamp); |
| 5158 |
} |
| 5159 |
|
| 5160 |
static void |
| 5161 |
gdk_win32_window_begin_move_drag (GdkWindow *window, |
| 5162 |
GdkDevice *device, |
| 5163 |
gint button, |
| 5164 |
gint root_x, |
| 5165 |
gint root_y, |
| 5166 |
guint32 timestamp) |
| 5167 |
{ |
| 5168 |
GdkWindowImplWin32 *impl; |
| 5169 |
|
| 5170 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5171 |
|
| 5172 |
if (GDK_WINDOW_DESTROYED (window) || |
| 5173 |
GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD || |
| 5174 |
IsIconic (GDK_WINDOW_HWND (window))) |
| 5175 |
return; |
| 5176 |
|
| 5177 |
/* Tell Windows to start interactively moving the window by pretending that |
| 5178 |
* the left pointer button was clicked in the titlebar. This will only work |
| 5179 |
* if the button is down when this function is called, and will only work |
| 5180 |
* with button 1 (left), since Windows only allows window dragging using the |
| 5181 |
* left mouse button. |
| 5182 |
*/ |
| 5183 |
if (button != 1) |
| 5184 |
return; |
| 5185 |
|
| 5186 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5187 |
|
| 5188 |
if (impl->drag_move_resize_context.op != GDK_WIN32_DRAGOP_NONE) |
| 5189 |
gdk_win32_window_end_move_resize_drag (window); |
| 5190 |
|
| 5191 |
setup_drag_move_resize_context (window, &impl->drag_move_resize_context, |
| 5192 |
GDK_WIN32_DRAGOP_MOVE, GDK_WINDOW_EDGE_NORTH_WEST, |
| 5193 |
device, button, root_x, root_y, timestamp); |
| 5194 |
} |
| 5195 |
|
| 5196 |
|
| 5197 |
/* |
| 5198 |
* Setting window states |
| 5199 |
*/ |
| 5200 |
static void |
| 5201 |
gdk_win32_window_iconify (GdkWindow *window) |
| 5202 |
{ |
| 5203 |
HWND old_active_window; |
| 5204 |
|
| 5205 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5206 |
|
| 5207 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5208 |
return; |
| 5209 |
|
| 5210 |
GDK_NOTE (MISC, g_print ("gdk_window_iconify: %p: %s\n", |
| 5211 |
GDK_WINDOW_HWND (window), |
| 5212 |
_gdk_win32_window_state_to_string (window->state))); |
| 5213 |
|
| 5214 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5215 |
{ |
| 5216 |
old_active_window = GetActiveWindow (); |
| 5217 |
GtkShowWindow (window, SW_MINIMIZE); |
| 5218 |
if (old_active_window != GDK_WINDOW_HWND (window)) |
| 5219 |
SetActiveWindow (old_active_window); |
| 5220 |
} |
| 5221 |
else |
| 5222 |
{ |
| 5223 |
gdk_synthesize_window_state (window, |
| 5224 |
0, |
| 5225 |
GDK_WINDOW_STATE_ICONIFIED); |
| 5226 |
} |
| 5227 |
} |
| 5228 |
|
| 5229 |
static void |
| 5230 |
gdk_win32_window_deiconify (GdkWindow *window) |
| 5231 |
{ |
| 5232 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5233 |
|
| 5234 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5235 |
return; |
| 5236 |
|
| 5237 |
GDK_NOTE (MISC, g_print ("gdk_window_deiconify: %p: %s\n", |
| 5238 |
GDK_WINDOW_HWND (window), |
| 5239 |
_gdk_win32_window_state_to_string (window->state))); |
| 5240 |
|
| 5241 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5242 |
{ |
| 5243 |
show_window_internal (window, GDK_WINDOW_IS_MAPPED (window), TRUE); |
| 5244 |
} |
| 5245 |
else |
| 5246 |
{ |
| 5247 |
gdk_synthesize_window_state (window, |
| 5248 |
GDK_WINDOW_STATE_ICONIFIED, |
| 5249 |
0); |
| 5250 |
} |
| 5251 |
} |
| 5252 |
|
| 5253 |
static void |
| 5254 |
gdk_win32_window_stick (GdkWindow *window) |
| 5255 |
{ |
| 5256 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5257 |
|
| 5258 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5259 |
return; |
| 5260 |
|
| 5261 |
/* FIXME: Do something? */ |
| 5262 |
} |
| 5263 |
|
| 5264 |
static void |
| 5265 |
gdk_win32_window_unstick (GdkWindow *window) |
| 5266 |
{ |
| 5267 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5268 |
|
| 5269 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5270 |
return; |
| 5271 |
|
| 5272 |
/* FIXME: Do something? */ |
| 5273 |
} |
| 5274 |
|
| 5275 |
static void |
| 5276 |
gdk_win32_window_maximize (GdkWindow *window) |
| 5277 |
{ |
| 5278 |
|
| 5279 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5280 |
|
| 5281 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5282 |
return; |
| 5283 |
|
| 5284 |
GDK_NOTE (MISC, g_print ("gdk_window_maximize: %p: %s\n", |
| 5285 |
GDK_WINDOW_HWND (window), |
| 5286 |
_gdk_win32_window_state_to_string (window->state))); |
| 5287 |
|
| 5288 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5289 |
GtkShowWindow (window, SW_MAXIMIZE); |
| 5290 |
else |
| 5291 |
gdk_synthesize_window_state (window, |
| 5292 |
0, |
| 5293 |
GDK_WINDOW_STATE_MAXIMIZED); |
| 5294 |
} |
| 5295 |
|
| 5296 |
static void |
| 5297 |
gdk_win32_window_unmaximize (GdkWindow *window) |
| 5298 |
{ |
| 5299 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5300 |
|
| 5301 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5302 |
return; |
| 5303 |
|
| 5304 |
GDK_NOTE (MISC, g_print ("gdk_window_unmaximize: %p: %s\n", |
| 5305 |
GDK_WINDOW_HWND (window), |
| 5306 |
_gdk_win32_window_state_to_string (window->state))); |
| 5307 |
|
| 5308 |
gdk_win32_window_invalidate_egl_framebuffer (window); |
| 5309 |
|
| 5310 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5311 |
GtkShowWindow (window, SW_RESTORE); |
| 5312 |
else |
| 5313 |
gdk_synthesize_window_state (window, |
| 5314 |
GDK_WINDOW_STATE_MAXIMIZED, |
| 5315 |
0); |
| 5316 |
} |
| 5317 |
|
| 5318 |
static void |
| 5319 |
gdk_win32_window_fullscreen (GdkWindow *window) |
| 5320 |
{ |
| 5321 |
gint x, y, width, height; |
| 5322 |
FullscreenInfo *fi; |
| 5323 |
HMONITOR monitor; |
| 5324 |
MONITORINFO mi; |
| 5325 |
DWORD extra_styles = WS_POPUP; |
| 5326 |
gint workaround_padding = 0; |
| 5327 |
|
| 5328 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5329 |
|
| 5330 |
fi = g_new (FullscreenInfo, 1); |
| 5331 |
|
| 5332 |
if (!GetWindowRect (GDK_WINDOW_HWND (window), &(fi->r))) |
| 5333 |
g_free (fi); |
| 5334 |
else |
| 5335 |
{ |
| 5336 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5337 |
|
| 5338 |
monitor = MonitorFromWindow (GDK_WINDOW_HWND (window), MONITOR_DEFAULTTONEAREST); |
| 5339 |
mi.cbSize = sizeof (mi); |
| 5340 |
if (monitor && GetMonitorInfo (monitor, &mi)) |
| 5341 |
{ |
| 5342 |
x = mi.rcMonitor.left; |
| 5343 |
y = mi.rcMonitor.top; |
| 5344 |
width = mi.rcMonitor.right - x; |
| 5345 |
height = mi.rcMonitor.bottom - y; |
| 5346 |
} |
| 5347 |
else |
| 5348 |
{ |
| 5349 |
x = y = 0; |
| 5350 |
width = GetSystemMetrics (SM_CXSCREEN); |
| 5351 |
height = GetSystemMetrics (SM_CYSCREEN); |
| 5352 |
} |
| 5353 |
|
| 5354 |
/* remember for restoring */ |
| 5355 |
fi->hint_flags = impl->hint_flags; |
| 5356 |
impl->hint_flags &= ~GDK_HINT_MAX_SIZE; |
| 5357 |
g_object_set_data (G_OBJECT (window), "fullscreen-info", fi); |
| 5358 |
fi->style = GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE); |
| 5359 |
|
| 5360 |
/* Send state change before configure event */ |
| 5361 |
gdk_synthesize_window_state (window, 0, GDK_WINDOW_STATE_FULLSCREEN); |
| 5362 |
|
| 5363 |
/* If we are using GL windows, and we set the envvar GDK_WIN32_GL_FULLSCREEN_WORKAROUND, |
| 5364 |
* set the WS_BORDER style so that DWM will not get deactivated. This is necessary |
| 5365 |
* when menus could not be shown correctly in fullscreen GL windows. To avoid seeing |
| 5366 |
* a border, we intentionally make the window bigger by 1px on all sides and place the |
| 5367 |
* window just 1px outside the top left-hand coordinates outside the screen area. |
| 5368 |
*/ |
| 5369 |
if (window->gl_paint_context != NULL && g_getenv ("GDK_WIN32_GL_FULLSCREEN_WORKAROUND")) |
| 5370 |
{ |
| 5371 |
extra_styles |= WS_BORDER; |
| 5372 |
workaround_padding = 1; |
| 5373 |
GDK_NOTE (MISC, g_print ("GL fullscreen workaround enabled for window [%p]\n", |
| 5374 |
GDK_WINDOW_HWND (window))); |
| 5375 |
} |
| 5376 |
|
| 5377 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, |
| 5378 |
(fi->style & ~WS_OVERLAPPEDWINDOW) | extra_styles); |
| 5379 |
|
| 5380 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_TOP, |
| 5381 |
x - workaround_padding, |
| 5382 |
y - workaround_padding, |
| 5383 |
width + (workaround_padding * 2), |
| 5384 |
height + (workaround_padding * 2), |
| 5385 |
SWP_NOCOPYBITS | SWP_SHOWWINDOW)); |
| 5386 |
} |
| 5387 |
} |
| 5388 |
|
| 5389 |
static void |
| 5390 |
gdk_win32_window_unfullscreen (GdkWindow *window) |
| 5391 |
{ |
| 5392 |
FullscreenInfo *fi; |
| 5393 |
|
| 5394 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5395 |
|
| 5396 |
fi = g_object_get_data (G_OBJECT (window), "fullscreen-info"); |
| 5397 |
if (fi) |
| 5398 |
{ |
| 5399 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5400 |
|
| 5401 |
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_FULLSCREEN, 0); |
| 5402 |
|
| 5403 |
impl->hint_flags = fi->hint_flags; |
| 5404 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, fi->style); |
| 5405 |
gdk_win32_window_invalidate_egl_framebuffer (window); |
| 5406 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), HWND_NOTOPMOST, |
| 5407 |
fi->r.left, fi->r.top, |
| 5408 |
fi->r.right - fi->r.left, fi->r.bottom - fi->r.top, |
| 5409 |
SWP_NOCOPYBITS | SWP_SHOWWINDOW)); |
| 5410 |
|
| 5411 |
g_object_set_data (G_OBJECT (window), "fullscreen-info", NULL); |
| 5412 |
g_free (fi); |
| 5413 |
_gdk_win32_window_update_style_bits (window); |
| 5414 |
} |
| 5415 |
} |
| 5416 |
|
| 5417 |
static void |
| 5418 |
gdk_win32_window_set_keep_above (GdkWindow *window, |
| 5419 |
gboolean setting) |
| 5420 |
{ |
| 5421 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5422 |
|
| 5423 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5424 |
return; |
| 5425 |
|
| 5426 |
GDK_NOTE (MISC, g_print ("gdk_window_set_keep_above: %p: %s\n", |
| 5427 |
GDK_WINDOW_HWND (window), |
| 5428 |
setting ? "YES" : "NO")); |
| 5429 |
|
| 5430 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5431 |
{ |
| 5432 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 5433 |
setting ? HWND_TOPMOST : HWND_NOTOPMOST, |
| 5434 |
0, 0, 0, 0, |
| 5435 |
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE)); |
| 5436 |
} |
| 5437 |
|
| 5438 |
gdk_synthesize_window_state (window, |
| 5439 |
setting ? GDK_WINDOW_STATE_BELOW : GDK_WINDOW_STATE_ABOVE, |
| 5440 |
setting ? GDK_WINDOW_STATE_ABOVE : 0); |
| 5441 |
} |
| 5442 |
|
| 5443 |
static void |
| 5444 |
gdk_win32_window_set_keep_below (GdkWindow *window, |
| 5445 |
gboolean setting) |
| 5446 |
{ |
| 5447 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5448 |
|
| 5449 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5450 |
return; |
| 5451 |
|
| 5452 |
GDK_NOTE (MISC, g_print ("gdk_window_set_keep_below: %p: %s\n", |
| 5453 |
GDK_WINDOW_HWND (window), |
| 5454 |
setting ? "YES" : "NO")); |
| 5455 |
|
| 5456 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5457 |
{ |
| 5458 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 5459 |
setting ? HWND_BOTTOM : HWND_NOTOPMOST, |
| 5460 |
0, 0, 0, 0, |
| 5461 |
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE)); |
| 5462 |
} |
| 5463 |
|
| 5464 |
gdk_synthesize_window_state (window, |
| 5465 |
setting ? GDK_WINDOW_STATE_ABOVE : GDK_WINDOW_STATE_BELOW, |
| 5466 |
setting ? GDK_WINDOW_STATE_BELOW : 0); |
| 5467 |
} |
| 5468 |
|
| 5469 |
static void |
| 5470 |
gdk_win32_window_focus (GdkWindow *window, |
| 5471 |
guint32 timestamp) |
| 5472 |
{ |
| 5473 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5474 |
|
| 5475 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5476 |
return; |
| 5477 |
|
| 5478 |
GDK_NOTE (MISC, g_print ("gdk_window_focus: %p: %s\n", |
| 5479 |
GDK_WINDOW_HWND (window), |
| 5480 |
_gdk_win32_window_state_to_string (window->state))); |
| 5481 |
|
| 5482 |
if (window->state & GDK_WINDOW_STATE_MAXIMIZED) |
| 5483 |
GtkShowWindow (window, SW_SHOWMAXIMIZED); |
| 5484 |
else if (window->state & GDK_WINDOW_STATE_ICONIFIED) |
| 5485 |
GtkShowWindow (window, SW_RESTORE); |
| 5486 |
else if (!IsWindowVisible (GDK_WINDOW_HWND (window))) |
| 5487 |
GtkShowWindow (window, SW_SHOWNORMAL); |
| 5488 |
else |
| 5489 |
GtkShowWindow (window, SW_SHOW); |
| 5490 |
|
| 5491 |
SetFocus (GDK_WINDOW_HWND (window)); |
| 5492 |
} |
| 5493 |
|
| 5494 |
static void |
| 5495 |
gdk_win32_window_set_modal_hint (GdkWindow *window, |
| 5496 |
gboolean modal) |
| 5497 |
{ |
| 5498 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5499 |
|
| 5500 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5501 |
return; |
| 5502 |
|
| 5503 |
GDK_NOTE (MISC, g_print ("gdk_window_set_modal_hint: %p: %s\n", |
| 5504 |
GDK_WINDOW_HWND (window), |
| 5505 |
modal ? "YES" : "NO")); |
| 5506 |
|
| 5507 |
if (modal == window->modal_hint) |
| 5508 |
return; |
| 5509 |
|
| 5510 |
window->modal_hint = modal; |
| 5511 |
|
| 5512 |
#if 0 |
| 5513 |
/* Not sure about this one.. -- Cody */ |
| 5514 |
if (GDK_WINDOW_IS_MAPPED (window)) |
| 5515 |
API_CALL (SetWindowPos, (GDK_WINDOW_HWND (window), |
| 5516 |
modal ? HWND_TOPMOST : HWND_NOTOPMOST, |
| 5517 |
0, 0, 0, 0, |
| 5518 |
SWP_NOMOVE | SWP_NOSIZE)); |
| 5519 |
#else |
| 5520 |
|
| 5521 |
if (modal) |
| 5522 |
{ |
| 5523 |
_gdk_push_modal_window (window); |
| 5524 |
gdk_window_raise (window); |
| 5525 |
} |
| 5526 |
else |
| 5527 |
{ |
| 5528 |
_gdk_remove_modal_window (window); |
| 5529 |
} |
| 5530 |
|
| 5531 |
#endif |
| 5532 |
} |
| 5533 |
|
| 5534 |
static void |
| 5535 |
gdk_win32_window_set_skip_taskbar_hint (GdkWindow *window, |
| 5536 |
gboolean skips_taskbar) |
| 5537 |
{ |
| 5538 |
static GdkWindow *owner = NULL; |
| 5539 |
//GdkWindowAttr wa; |
| 5540 |
|
| 5541 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5542 |
|
| 5543 |
GDK_NOTE (MISC, g_print ("gdk_window_set_skip_taskbar_hint: %p: %s, doing nothing\n", |
| 5544 |
GDK_WINDOW_HWND (window), |
| 5545 |
skips_taskbar ? "YES" : "NO")); |
| 5546 |
|
| 5547 |
// ### TODO: Need to figure out what to do here. |
| 5548 |
return; |
| 5549 |
|
| 5550 |
if (skips_taskbar) |
| 5551 |
{ |
| 5552 |
#if 0 |
| 5553 |
if (owner == NULL) |
| 5554 |
{ |
| 5555 |
wa.window_type = GDK_WINDOW_TEMP; |
| 5556 |
wa.wclass = GDK_INPUT_OUTPUT; |
| 5557 |
wa.width = wa.height = 1; |
| 5558 |
wa.event_mask = 0; |
| 5559 |
owner = gdk_window_new_internal (NULL, &wa, 0, TRUE); |
| 5560 |
} |
| 5561 |
#endif |
| 5562 |
|
| 5563 |
SetWindowLongPtr (GDK_WINDOW_HWND (window), GWLP_HWNDPARENT, (LONG_PTR) GDK_WINDOW_HWND (owner)); |
| 5564 |
|
| 5565 |
#if 0 /* Should we also turn off the minimize and maximize buttons? */ |
| 5566 |
SetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE, |
| 5567 |
GetWindowLong (GDK_WINDOW_HWND (window), GWL_STYLE) & ~(WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU)); |
| 5568 |
|
| 5569 |
SetWindowPos (GDK_WINDOW_HWND (window), SWP_NOZORDER_SPECIFIED, |
| 5570 |
0, 0, 0, 0, |
| 5571 |
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | |
| 5572 |
SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); |
| 5573 |
#endif |
| 5574 |
} |
| 5575 |
else |
| 5576 |
{ |
| 5577 |
SetWindowLongPtr (GDK_WINDOW_HWND (window), GWLP_HWNDPARENT, 0); |
| 5578 |
} |
| 5579 |
} |
| 5580 |
|
| 5581 |
static void |
| 5582 |
gdk_win32_window_set_skip_pager_hint (GdkWindow *window, |
| 5583 |
gboolean skips_pager) |
| 5584 |
{ |
| 5585 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5586 |
|
| 5587 |
GDK_NOTE (MISC, g_print ("gdk_window_set_skip_pager_hint: %p: %s, doing nothing\n", |
| 5588 |
GDK_WINDOW_HWND (window), |
| 5589 |
skips_pager ? "YES" : "NO")); |
| 5590 |
} |
| 5591 |
|
| 5592 |
static void |
| 5593 |
gdk_win32_window_set_type_hint (GdkWindow *window, |
| 5594 |
GdkWindowTypeHint hint) |
| 5595 |
{ |
| 5596 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5597 |
|
| 5598 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5599 |
return; |
| 5600 |
|
| 5601 |
GDK_NOTE (MISC, |
| 5602 |
G_STMT_START{ |
| 5603 |
static GEnumClass *class = NULL; |
| 5604 |
if (!class) |
| 5605 |
class = g_type_class_ref (GDK_TYPE_WINDOW_TYPE_HINT); |
| 5606 |
g_print ("gdk_window_set_type_hint: %p: %s\n", |
| 5607 |
GDK_WINDOW_HWND (window), |
| 5608 |
g_enum_get_value (class, hint)->value_name); |
| 5609 |
}G_STMT_END); |
| 5610 |
|
| 5611 |
((GdkWindowImplWin32 *)window->impl)->type_hint = hint; |
| 5612 |
|
| 5613 |
_gdk_win32_window_update_style_bits (window); |
| 5614 |
} |
| 5615 |
|
| 5616 |
static GdkWindowTypeHint |
| 5617 |
gdk_win32_window_get_type_hint (GdkWindow *window) |
| 5618 |
{ |
| 5619 |
g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL); |
| 5620 |
|
| 5621 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5622 |
return GDK_WINDOW_TYPE_HINT_NORMAL; |
| 5623 |
|
| 5624 |
return GDK_WINDOW_IMPL_WIN32 (window->impl)->type_hint; |
| 5625 |
} |
| 5626 |
|
| 5627 |
static HRGN |
| 5628 |
cairo_region_to_hrgn (const cairo_region_t *region, |
| 5629 |
gint x_origin, |
| 5630 |
gint y_origin, |
| 5631 |
guint scale) |
| 5632 |
{ |
| 5633 |
HRGN hrgn; |
| 5634 |
RGNDATA *rgndata; |
| 5635 |
RECT *rect; |
| 5636 |
cairo_rectangle_int_t r; |
| 5637 |
const int nrects = cairo_region_num_rectangles (region); |
| 5638 |
guint nbytes = |
| 5639 |
sizeof (RGNDATAHEADER) + (sizeof (RECT) * nrects); |
| 5640 |
int i; |
| 5641 |
|
| 5642 |
rgndata = g_malloc (nbytes); |
| 5643 |
rgndata->rdh.dwSize = sizeof (RGNDATAHEADER); |
| 5644 |
rgndata->rdh.iType = RDH_RECTANGLES; |
| 5645 |
rgndata->rdh.nCount = rgndata->rdh.nRgnSize = 0; |
| 5646 |
SetRect (&rgndata->rdh.rcBound, |
| 5647 |
G_MAXLONG, G_MAXLONG, G_MINLONG, G_MINLONG); |
| 5648 |
|
| 5649 |
for (i = 0; i < nrects; i++) |
| 5650 |
{ |
| 5651 |
rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++; |
| 5652 |
|
| 5653 |
cairo_region_get_rectangle (region, i, &r); |
| 5654 |
rect->left = (r.x + x_origin) * scale; |
| 5655 |
rect->right = (rect->left + r.width) * scale; |
| 5656 |
rect->top = (r.y + y_origin) * scale; |
| 5657 |
rect->bottom = (rect->top + r.height) * scale; |
| 5658 |
|
| 5659 |
if (rect->left < rgndata->rdh.rcBound.left) |
| 5660 |
rgndata->rdh.rcBound.left = rect->left; |
| 5661 |
if (rect->right > rgndata->rdh.rcBound.right) |
| 5662 |
rgndata->rdh.rcBound.right = rect->right; |
| 5663 |
if (rect->top < rgndata->rdh.rcBound.top) |
| 5664 |
rgndata->rdh.rcBound.top = rect->top; |
| 5665 |
if (rect->bottom > rgndata->rdh.rcBound.bottom) |
| 5666 |
rgndata->rdh.rcBound.bottom = rect->bottom; |
| 5667 |
} |
| 5668 |
if ((hrgn = ExtCreateRegion (NULL, nbytes, rgndata)) == NULL) |
| 5669 |
WIN32_API_FAILED ("ExtCreateRegion"); |
| 5670 |
|
| 5671 |
g_free (rgndata); |
| 5672 |
|
| 5673 |
return (hrgn); |
| 5674 |
} |
| 5675 |
|
| 5676 |
static void |
| 5677 |
gdk_win32_window_shape_combine_region (GdkWindow *window, |
| 5678 |
const cairo_region_t *shape_region, |
| 5679 |
gint offset_x, |
| 5680 |
gint offset_y) |
| 5681 |
{ |
| 5682 |
GdkWindowImplWin32 *impl; |
| 5683 |
|
| 5684 |
if (GDK_WINDOW_DESTROYED (window)) |
| 5685 |
return; |
| 5686 |
|
| 5687 |
if (!shape_region) |
| 5688 |
{ |
| 5689 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_shape_combine_region: %p: none\n", |
| 5690 |
GDK_WINDOW_HWND (window))); |
| 5691 |
SetWindowRgn (GDK_WINDOW_HWND (window), NULL, TRUE); |
| 5692 |
} |
| 5693 |
else |
| 5694 |
{ |
| 5695 |
HRGN hrgn; |
| 5696 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5697 |
|
| 5698 |
hrgn = cairo_region_to_hrgn (shape_region, 0, 0, impl->window_scale); |
| 5699 |
|
| 5700 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_shape_combine_region: %p: %p\n", |
| 5701 |
GDK_WINDOW_HWND (window), |
| 5702 |
hrgn)); |
| 5703 |
|
| 5704 |
do_shape_combine_region (window, hrgn, offset_x, offset_y); |
| 5705 |
} |
| 5706 |
} |
| 5707 |
|
| 5708 |
GdkWindow * |
| 5709 |
gdk_win32_window_lookup_for_display (GdkDisplay *display, |
| 5710 |
HWND anid) |
| 5711 |
{ |
| 5712 |
g_return_val_if_fail (display == gdk_display_get_default (), NULL); |
| 5713 |
|
| 5714 |
return (GdkWindow*) gdk_win32_handle_table_lookup (anid); |
| 5715 |
} |
| 5716 |
|
| 5717 |
static void |
| 5718 |
gdk_win32_window_set_opacity (GdkWindow *window, |
| 5719 |
gdouble opacity) |
| 5720 |
{ |
| 5721 |
LONG exstyle; |
| 5722 |
typedef BOOL (WINAPI *PFN_SetLayeredWindowAttributes) (HWND, COLORREF, BYTE, DWORD); |
| 5723 |
PFN_SetLayeredWindowAttributes setLayeredWindowAttributes = NULL; |
| 5724 |
GdkWindowImplWin32 *impl; |
| 5725 |
|
| 5726 |
g_return_if_fail (GDK_IS_WINDOW (window)); |
| 5727 |
|
| 5728 |
if (!WINDOW_IS_TOPLEVEL (window) || GDK_WINDOW_DESTROYED (window)) |
| 5729 |
return; |
| 5730 |
|
| 5731 |
if (opacity < 0) |
| 5732 |
opacity = 0; |
| 5733 |
else if (opacity > 1) |
| 5734 |
opacity = 1; |
| 5735 |
|
| 5736 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5737 |
|
| 5738 |
if (impl->layered) |
| 5739 |
{ |
| 5740 |
if (impl->layered_opacity != opacity) |
| 5741 |
{ |
| 5742 |
RECT window_rect; |
| 5743 |
|
| 5744 |
impl->layered_opacity = opacity; |
| 5745 |
|
| 5746 |
gdk_win32_get_window_client_area_rect (window, impl->window_scale, &window_rect); |
| 5747 |
gdk_win32_update_layered_window_from_cache (window, &window_rect); |
| 5748 |
} |
| 5749 |
|
| 5750 |
return; |
| 5751 |
} |
| 5752 |
|
| 5753 |
exstyle = GetWindowLong (GDK_WINDOW_HWND (window), GWL_EXSTYLE); |
| 5754 |
|
| 5755 |
if (!(exstyle & WS_EX_LAYERED)) |
| 5756 |
SetWindowLong (GDK_WINDOW_HWND (window), |
| 5757 |
GWL_EXSTYLE, |
| 5758 |
exstyle | WS_EX_LAYERED); |
| 5759 |
|
| 5760 |
setLayeredWindowAttributes = |
| 5761 |
(PFN_SetLayeredWindowAttributes)GetProcAddress (GetModuleHandle ("user32.dll"), "SetLayeredWindowAttributes"); |
| 5762 |
|
| 5763 |
if (setLayeredWindowAttributes) |
| 5764 |
{ |
| 5765 |
API_CALL (setLayeredWindowAttributes, (GDK_WINDOW_HWND (window), |
| 5766 |
0, |
| 5767 |
opacity * 0xff, |
| 5768 |
LWA_ALPHA)); |
| 5769 |
} |
| 5770 |
} |
| 5771 |
|
| 5772 |
static cairo_region_t * |
| 5773 |
gdk_win32_window_get_shape (GdkWindow *window) |
| 5774 |
{ |
| 5775 |
HRGN hrgn = CreateRectRgn (0, 0, 0, 0); |
| 5776 |
int type = GetWindowRgn (GDK_WINDOW_HWND (window), hrgn); |
| 5777 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5778 |
|
| 5779 |
if (type == SIMPLEREGION || type == COMPLEXREGION) |
| 5780 |
{ |
| 5781 |
cairo_region_t *region = _gdk_win32_hrgn_to_region (hrgn, impl->window_scale); |
| 5782 |
|
| 5783 |
DeleteObject (hrgn); |
| 5784 |
return region; |
| 5785 |
} |
| 5786 |
|
| 5787 |
return NULL; |
| 5788 |
} |
| 5789 |
|
| 5790 |
static void |
| 5791 |
gdk_win32_input_shape_combine_region (GdkWindow *window, |
| 5792 |
const cairo_region_t *shape_region, |
| 5793 |
gint offset_x, |
| 5794 |
gint offset_y) |
| 5795 |
{ |
| 5796 |
/* Partial input shape support is implemented by handling the |
| 5797 |
* WM_NCHITTEST message. |
| 5798 |
*/ |
| 5799 |
} |
| 5800 |
|
| 5801 |
gboolean |
| 5802 |
gdk_win32_window_is_win32 (GdkWindow *window) |
| 5803 |
{ |
| 5804 |
return GDK_WINDOW_IS_WIN32 (window); |
| 5805 |
} |
| 5806 |
|
| 5807 |
static gboolean |
| 5808 |
gdk_win32_window_show_window_menu (GdkWindow *window, |
| 5809 |
GdkEvent *event) |
| 5810 |
{ |
| 5811 |
double event_x, event_y; |
| 5812 |
gint x, y; |
| 5813 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 5814 |
|
| 5815 |
switch (event->type) |
| 5816 |
{ |
| 5817 |
case GDK_BUTTON_PRESS: |
| 5818 |
case GDK_BUTTON_RELEASE: |
| 5819 |
case GDK_TOUCH_BEGIN: |
| 5820 |
case GDK_TOUCH_END: |
| 5821 |
break; |
| 5822 |
default: |
| 5823 |
return FALSE; |
| 5824 |
} |
| 5825 |
|
| 5826 |
gdk_event_get_root_coords (event, &event_x, &event_y); |
| 5827 |
x = event_x * impl->window_scale - _gdk_offset_x; |
| 5828 |
y = event_y * impl->window_scale - _gdk_offset_y; |
| 5829 |
|
| 5830 |
SendMessage (GDK_WINDOW_HWND (window), |
| 5831 |
WM_SYSMENU, |
| 5832 |
0, |
| 5833 |
MAKELPARAM (x, y)); |
| 5834 |
|
| 5835 |
return TRUE; |
| 5836 |
} |
| 5837 |
|
| 5838 |
/** |
| 5839 |
* _gdk_win32_acquire_dc |
| 5840 |
* @impl: a Win32 #GdkWindowImplWin32 implementation |
| 5841 |
* |
| 5842 |
* Gets a DC with the given drawable selected into it. |
| 5843 |
* |
| 5844 |
* Returns: The DC, on success. Otherwise |
| 5845 |
* %NULL. If this function succeeded |
| 5846 |
* _gdk_win32_impl_release_dc() must be called |
| 5847 |
* release the DC when you are done using it. |
| 5848 |
**/ |
| 5849 |
static HDC |
| 5850 |
_gdk_win32_impl_acquire_dc (GdkWindowImplWin32 *impl) |
| 5851 |
{ |
| 5852 |
if (GDK_IS_WINDOW_IMPL_WIN32 (impl) && |
| 5853 |
GDK_WINDOW_DESTROYED (impl->wrapper)) |
| 5854 |
return NULL; |
| 5855 |
|
| 5856 |
/* We don't call this function for layered windows, but |
| 5857 |
* in case we do... |
| 5858 |
*/ |
| 5859 |
if (impl->layered) |
| 5860 |
return NULL; |
| 5861 |
|
| 5862 |
if (!impl->hdc) |
| 5863 |
{ |
| 5864 |
impl->hdc = GetDC (impl->handle); |
| 5865 |
if (!impl->hdc) |
| 5866 |
WIN32_GDI_FAILED ("GetDC"); |
| 5867 |
} |
| 5868 |
|
| 5869 |
if (impl->hdc) |
| 5870 |
{ |
| 5871 |
impl->hdc_count++; |
| 5872 |
return impl->hdc; |
| 5873 |
} |
| 5874 |
else |
| 5875 |
{ |
| 5876 |
return NULL; |
| 5877 |
} |
| 5878 |
} |
| 5879 |
|
| 5880 |
/** |
| 5881 |
* _gdk_win32_impl_release_dc |
| 5882 |
* @impl: a Win32 #GdkWindowImplWin32 implementation |
| 5883 |
* |
| 5884 |
* Releases the reference count for the DC |
| 5885 |
* from _gdk_win32_impl_acquire_dc() |
| 5886 |
**/ |
| 5887 |
static void |
| 5888 |
_gdk_win32_impl_release_dc (GdkWindowImplWin32 *impl) |
| 5889 |
{ |
| 5890 |
if (impl->layered) |
| 5891 |
return; |
| 5892 |
|
| 5893 |
g_return_if_fail (impl->hdc_count > 0); |
| 5894 |
|
| 5895 |
impl->hdc_count--; |
| 5896 |
if (impl->hdc_count == 0) |
| 5897 |
{ |
| 5898 |
if (impl->saved_dc_bitmap) |
| 5899 |
{ |
| 5900 |
GDI_CALL (SelectObject, (impl->hdc, impl->saved_dc_bitmap)); |
| 5901 |
impl->saved_dc_bitmap = NULL; |
| 5902 |
} |
| 5903 |
|
| 5904 |
if (impl->hdc) |
| 5905 |
{ |
| 5906 |
GDI_CALL (ReleaseDC, (impl->handle, impl->hdc)); |
| 5907 |
impl->hdc = NULL; |
| 5908 |
} |
| 5909 |
} |
| 5910 |
} |
| 5911 |
|
| 5912 |
HWND |
| 5913 |
gdk_win32_window_get_impl_hwnd (GdkWindow *window) |
| 5914 |
{ |
| 5915 |
if (GDK_WINDOW_IS_WIN32 (window)) |
| 5916 |
return GDK_WINDOW_HWND (window); |
| 5917 |
return NULL; |
| 5918 |
} |
| 5919 |
|
| 5920 |
static void |
| 5921 |
gdk_win32_cairo_surface_destroy (void *data) |
| 5922 |
{ |
| 5923 |
GdkWindowImplWin32 *impl = data; |
| 5924 |
|
| 5925 |
_gdk_win32_impl_release_dc (impl); |
| 5926 |
impl->cairo_surface = NULL; |
| 5927 |
} |
| 5928 |
|
| 5929 |
static cairo_surface_t * |
| 5930 |
gdk_win32_ref_cairo_surface_layered (GdkWindow *window, |
| 5931 |
GdkWindowImplWin32 *impl) |
| 5932 |
{ |
| 5933 |
gint width, height; |
| 5934 |
RECT window_rect; |
| 5935 |
|
| 5936 |
gdk_win32_get_window_client_area_rect (window, impl->window_scale, &window_rect); |
| 5937 |
|
| 5938 |
/* Turn client area into window area */ |
| 5939 |
_gdk_win32_adjust_client_rect (window, &window_rect); |
| 5940 |
|
| 5941 |
width = window_rect.right - window_rect.left; |
| 5942 |
height = window_rect.bottom - window_rect.top; |
| 5943 |
|
| 5944 |
if (width > impl->dib_width || |
| 5945 |
height > impl->dib_height) |
| 5946 |
{ |
| 5947 |
cairo_surface_t *new_cache; |
| 5948 |
cairo_t *cr; |
| 5949 |
|
| 5950 |
/* Create larger cache surface, copy old cache surface over it */ |
| 5951 |
new_cache = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, |
| 5952 |
width, |
| 5953 |
height); |
| 5954 |
|
| 5955 |
if (impl->cache_surface) |
| 5956 |
{ |
| 5957 |
cr = cairo_create (new_cache); |
| 5958 |
cairo_set_source_surface (cr, impl->cache_surface, 0, 0); |
| 5959 |
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
| 5960 |
cairo_paint (cr); |
| 5961 |
cairo_destroy (cr); |
| 5962 |
cairo_surface_flush (new_cache); |
| 5963 |
|
| 5964 |
cairo_surface_destroy (impl->cache_surface); |
| 5965 |
} |
| 5966 |
|
| 5967 |
impl->cache_surface = new_cache; |
| 5968 |
|
| 5969 |
cairo_surface_set_device_scale (impl->cache_surface, |
| 5970 |
impl->window_scale, |
| 5971 |
impl->window_scale); |
| 5972 |
|
| 5973 |
if (impl->cairo_surface) |
| 5974 |
cairo_surface_destroy (impl->cairo_surface); |
| 5975 |
|
| 5976 |
impl->cairo_surface = NULL; |
| 5977 |
} |
| 5978 |
|
| 5979 |
/* This is separate, because cairo_surface gets killed |
| 5980 |
* off frequently by outside code, whereas cache_surface |
| 5981 |
* is only killed by us, above. |
| 5982 |
*/ |
| 5983 |
if (!impl->cairo_surface) |
| 5984 |
{ |
| 5985 |
impl->cairo_surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, |
| 5986 |
width, |
| 5987 |
height); |
| 5988 |
impl->dib_width = width; |
| 5989 |
impl->dib_height = height; |
| 5990 |
|
| 5991 |
cairo_surface_set_device_scale (impl->cairo_surface, |
| 5992 |
impl->window_scale, |
| 5993 |
impl->window_scale); |
| 5994 |
|
| 5995 |
cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key, |
| 5996 |
impl, gdk_win32_cairo_surface_destroy); |
| 5997 |
} |
| 5998 |
else |
| 5999 |
{ |
| 6000 |
cairo_surface_reference (impl->cairo_surface); |
| 6001 |
} |
| 6002 |
|
| 6003 |
return impl->cairo_surface; |
| 6004 |
} |
| 6005 |
|
| 6006 |
static cairo_surface_t * |
| 6007 |
gdk_win32_ref_cairo_surface (GdkWindow *window) |
| 6008 |
{ |
| 6009 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6010 |
|
| 6011 |
if (GDK_IS_WINDOW_IMPL_WIN32 (impl) && |
| 6012 |
GDK_WINDOW_DESTROYED (impl->wrapper)) |
| 6013 |
return NULL; |
| 6014 |
|
| 6015 |
if (impl->layered) |
| 6016 |
return gdk_win32_ref_cairo_surface_layered (window, impl); |
| 6017 |
|
| 6018 |
if (!impl->cairo_surface) |
| 6019 |
{ |
| 6020 |
HDC hdc = _gdk_win32_impl_acquire_dc (impl); |
| 6021 |
if (!hdc) |
| 6022 |
return NULL; |
| 6023 |
|
| 6024 |
impl->cairo_surface = cairo_win32_surface_create_with_format (hdc, CAIRO_FORMAT_ARGB32); |
| 6025 |
cairo_surface_set_device_scale (impl->cairo_surface, |
| 6026 |
impl->window_scale, |
| 6027 |
impl->window_scale); |
| 6028 |
|
| 6029 |
cairo_surface_set_user_data (impl->cairo_surface, &gdk_win32_cairo_key, |
| 6030 |
impl, gdk_win32_cairo_surface_destroy); |
| 6031 |
} |
| 6032 |
else |
| 6033 |
cairo_surface_reference (impl->cairo_surface); |
| 6034 |
|
| 6035 |
return impl->cairo_surface; |
| 6036 |
} |
| 6037 |
|
| 6038 |
BOOL WINAPI |
| 6039 |
GtkShowWindow (GdkWindow *window, |
| 6040 |
int cmd_show) |
| 6041 |
{ |
| 6042 |
cairo_t *cr; |
| 6043 |
cairo_surface_t *surface; |
| 6044 |
RECT window_rect; |
| 6045 |
HDC hdc; |
| 6046 |
POINT window_position; |
| 6047 |
SIZE window_size; |
| 6048 |
POINT source_point; |
| 6049 |
BLENDFUNCTION blender; |
| 6050 |
|
| 6051 |
HWND hwnd = GDK_WINDOW_HWND (window); |
| 6052 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6053 |
|
| 6054 |
switch (cmd_show) |
| 6055 |
{ |
| 6056 |
case SW_FORCEMINIMIZE: |
| 6057 |
case SW_HIDE: |
| 6058 |
case SW_MINIMIZE: |
| 6059 |
break; |
| 6060 |
case SW_MAXIMIZE: |
| 6061 |
case SW_RESTORE: |
| 6062 |
case SW_SHOW: |
| 6063 |
case SW_SHOWDEFAULT: |
| 6064 |
case SW_SHOWMINIMIZED: |
| 6065 |
case SW_SHOWMINNOACTIVE: |
| 6066 |
case SW_SHOWNA: |
| 6067 |
case SW_SHOWNOACTIVATE: |
| 6068 |
case SW_SHOWNORMAL: |
| 6069 |
|
| 6070 |
if (IsWindowVisible (hwnd)) |
| 6071 |
break; |
| 6072 |
|
| 6073 |
if ((WS_EX_LAYERED & GetWindowLongPtr (hwnd, GWL_EXSTYLE)) != WS_EX_LAYERED) |
| 6074 |
break; |
| 6075 |
|
| 6076 |
/* Window was hidden, will be shown. Erase it, GDK will repaint soon, |
| 6077 |
* but not soon enough, so it's possible to see old content before |
| 6078 |
* the next redraw, unless we erase the window first. |
| 6079 |
*/ |
| 6080 |
GetWindowRect (hwnd, &window_rect); |
| 6081 |
source_point.x = source_point.y = 0; |
| 6082 |
|
| 6083 |
window_position.x = window_rect.left; |
| 6084 |
window_position.y = window_rect.top; |
| 6085 |
window_size.cx = window_rect.right - window_rect.left; |
| 6086 |
window_size.cy = window_rect.bottom - window_rect.top; |
| 6087 |
|
| 6088 |
blender.BlendOp = AC_SRC_OVER; |
| 6089 |
blender.BlendFlags = 0; |
| 6090 |
blender.AlphaFormat = AC_SRC_ALPHA; |
| 6091 |
blender.SourceConstantAlpha = 255; |
| 6092 |
|
| 6093 |
/* Create a surface of appropriate size and clear it */ |
| 6094 |
surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, |
| 6095 |
window_size.cx, |
| 6096 |
window_size.cy); |
| 6097 |
cairo_surface_set_device_scale (surface, impl->window_scale, impl->window_scale); |
| 6098 |
cr = cairo_create (surface); |
| 6099 |
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); |
| 6100 |
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); |
| 6101 |
cairo_paint (cr); |
| 6102 |
cairo_destroy (cr); |
| 6103 |
cairo_surface_flush (surface); |
| 6104 |
hdc = cairo_win32_surface_get_dc (surface); |
| 6105 |
|
| 6106 |
/* No API_CALL() wrapper, don't check for errors */ |
| 6107 |
UpdateLayeredWindow (hwnd, NULL, |
| 6108 |
&window_position, &window_size, |
| 6109 |
hdc, &source_point, |
| 6110 |
0, &blender, ULW_ALPHA); |
| 6111 |
|
| 6112 |
cairo_surface_destroy (surface); |
| 6113 |
|
| 6114 |
break; |
| 6115 |
} |
| 6116 |
|
| 6117 |
/* Ensure that maximized window size is corrected later on */ |
| 6118 |
if (cmd_show == SW_MAXIMIZE) |
| 6119 |
impl->maximizing = TRUE; |
| 6120 |
|
| 6121 |
return ShowWindow (hwnd, cmd_show); |
| 6122 |
} |
| 6123 |
|
| 6124 |
static void |
| 6125 |
gdk_win32_window_set_shadow_width (GdkWindow *window, |
| 6126 |
gint left, |
| 6127 |
gint right, |
| 6128 |
gint top, |
| 6129 |
gint bottom) |
| 6130 |
{ |
| 6131 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6132 |
|
| 6133 |
if (GDK_WINDOW_DESTROYED (window)) |
| 6134 |
return; |
| 6135 |
|
| 6136 |
GDK_NOTE (MISC, g_print ("gdk_win32_window_set_shadow_width: window %p, " |
| 6137 |
"left %d, top %d, right %d, bottom %d\n", |
| 6138 |
window, left, top, right, bottom)); |
| 6139 |
|
| 6140 |
impl->zero_margins = left == 0 && right == 0 && top == 0 && bottom == 0; |
| 6141 |
|
| 6142 |
if (impl->zero_margins) |
| 6143 |
return; |
| 6144 |
|
| 6145 |
impl->margins.left = left; |
| 6146 |
impl->margins.right = right * impl->window_scale; |
| 6147 |
impl->margins.top = top; |
| 6148 |
impl->margins.bottom = bottom * impl->window_scale; |
| 6149 |
impl->margins_x = left + right; |
| 6150 |
impl->margins_y = top + bottom; |
| 6151 |
} |
| 6152 |
|
| 6153 |
|
| 6154 |
gint |
| 6155 |
_gdk_win32_window_get_scale_factor (GdkWindow *window) |
| 6156 |
{ |
| 6157 |
GdkDisplay *display; |
| 6158 |
GdkWindowImplWin32 *impl; |
| 6159 |
|
| 6160 |
GdkWin32Display *win32_display; |
| 6161 |
UINT dpix, dpiy; |
| 6162 |
gboolean is_scale_acquired; |
| 6163 |
|
| 6164 |
if (GDK_WINDOW_DESTROYED (window)) |
| 6165 |
return 1; |
| 6166 |
|
| 6167 |
g_return_val_if_fail (window != NULL, 1); |
| 6168 |
|
| 6169 |
display = gdk_window_get_display (window); |
| 6170 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6171 |
|
| 6172 |
win32_display = GDK_WIN32_DISPLAY (display); |
| 6173 |
|
| 6174 |
if (win32_display->dpi_aware_type != PROCESS_DPI_UNAWARE) |
| 6175 |
{ |
| 6176 |
if (win32_display->has_fixed_scale) |
| 6177 |
impl->window_scale = win32_display->window_scale; |
| 6178 |
else |
| 6179 |
impl->window_scale = _gdk_win32_display_get_monitor_scale_factor (win32_display, |
| 6180 |
NULL, |
| 6181 |
GDK_WINDOW_HWND (window), |
| 6182 |
NULL); |
| 6183 |
|
| 6184 |
return impl->window_scale; |
| 6185 |
} |
| 6186 |
else |
| 6187 |
{ |
| 6188 |
if (win32_display->has_fixed_scale) |
| 6189 |
{ |
| 6190 |
static gsize hidpi_msg_displayed = 0; |
| 6191 |
|
| 6192 |
if (g_once_init_enter (&hidpi_msg_displayed)) |
| 6193 |
{ |
| 6194 |
g_message ("Note: GDK_SCALE is ignored as HiDPI awareness is disabled."); |
| 6195 |
g_once_init_leave (&hidpi_msg_displayed, 1); |
| 6196 |
} |
| 6197 |
} |
| 6198 |
|
| 6199 |
/* Application is not DPI aware, don't bother */ |
| 6200 |
return 1; |
| 6201 |
} |
| 6202 |
} |
| 6203 |
|
| 6204 |
void |
| 6205 |
_gdk_win32_window_get_unscaled_size (GdkWindow *window, |
| 6206 |
gint *unscaled_width, |
| 6207 |
gint *unscaled_height) |
| 6208 |
{ |
| 6209 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6210 |
|
| 6211 |
if (unscaled_width) |
| 6212 |
*unscaled_width = impl->unscaled_width; |
| 6213 |
if (unscaled_height) |
| 6214 |
*unscaled_height = impl->unscaled_height; |
| 6215 |
} |
| 6216 |
|
| 6217 |
static void |
| 6218 |
gdk_window_impl_win32_class_init (GdkWindowImplWin32Class *klass) |
| 6219 |
{ |
| 6220 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 6221 |
GdkWindowImplClass *impl_class = GDK_WINDOW_IMPL_CLASS (klass); |
| 6222 |
|
| 6223 |
parent_class = g_type_class_peek_parent (klass); |
| 6224 |
|
| 6225 |
object_class->finalize = gdk_window_impl_win32_finalize; |
| 6226 |
|
| 6227 |
impl_class->ref_cairo_surface = gdk_win32_ref_cairo_surface; |
| 6228 |
|
| 6229 |
impl_class->show = gdk_win32_window_show; |
| 6230 |
impl_class->hide = gdk_win32_window_hide; |
| 6231 |
impl_class->withdraw = gdk_win32_window_withdraw; |
| 6232 |
impl_class->set_events = gdk_win32_window_set_events; |
| 6233 |
impl_class->get_events = gdk_win32_window_get_events; |
| 6234 |
impl_class->raise = gdk_win32_window_raise; |
| 6235 |
impl_class->lower = gdk_win32_window_lower; |
| 6236 |
impl_class->restack_under = gdk_win32_window_restack_under; |
| 6237 |
impl_class->restack_toplevel = gdk_win32_window_restack_toplevel; |
| 6238 |
impl_class->move_resize = gdk_win32_window_move_resize; |
| 6239 |
impl_class->set_background = gdk_win32_window_set_background; |
| 6240 |
impl_class->reparent = gdk_win32_window_reparent; |
| 6241 |
impl_class->set_device_cursor = gdk_win32_window_set_device_cursor; |
| 6242 |
impl_class->get_geometry = gdk_win32_window_get_geometry; |
| 6243 |
impl_class->get_device_state = gdk_window_win32_get_device_state; |
| 6244 |
impl_class->get_root_coords = gdk_win32_window_get_root_coords; |
| 6245 |
|
| 6246 |
impl_class->shape_combine_region = gdk_win32_window_shape_combine_region; |
| 6247 |
impl_class->input_shape_combine_region = gdk_win32_input_shape_combine_region; |
| 6248 |
impl_class->destroy = gdk_win32_window_destroy; |
| 6249 |
impl_class->destroy_foreign = gdk_win32_window_destroy_foreign; |
| 6250 |
impl_class->get_shape = gdk_win32_window_get_shape; |
| 6251 |
//FIXME?: impl_class->get_input_shape = gdk_win32_window_get_input_shape; |
| 6252 |
impl_class->begin_paint = gdk_win32_window_begin_paint; |
| 6253 |
impl_class->end_paint = gdk_win32_window_end_paint; |
| 6254 |
|
| 6255 |
//impl_class->beep = gdk_x11_window_beep; |
| 6256 |
|
| 6257 |
|
| 6258 |
impl_class->show_window_menu = gdk_win32_window_show_window_menu; |
| 6259 |
impl_class->focus = gdk_win32_window_focus; |
| 6260 |
impl_class->set_type_hint = gdk_win32_window_set_type_hint; |
| 6261 |
impl_class->get_type_hint = gdk_win32_window_get_type_hint; |
| 6262 |
impl_class->set_modal_hint = gdk_win32_window_set_modal_hint; |
| 6263 |
impl_class->set_skip_taskbar_hint = gdk_win32_window_set_skip_taskbar_hint; |
| 6264 |
impl_class->set_skip_pager_hint = gdk_win32_window_set_skip_pager_hint; |
| 6265 |
impl_class->set_urgency_hint = gdk_win32_window_set_urgency_hint; |
| 6266 |
impl_class->set_geometry_hints = gdk_win32_window_set_geometry_hints; |
| 6267 |
impl_class->set_title = gdk_win32_window_set_title; |
| 6268 |
impl_class->set_role = gdk_win32_window_set_role; |
| 6269 |
//impl_class->set_startup_id = gdk_x11_window_set_startup_id; |
| 6270 |
impl_class->set_transient_for = gdk_win32_window_set_transient_for; |
| 6271 |
impl_class->get_frame_extents = gdk_win32_window_get_frame_extents; |
| 6272 |
impl_class->set_override_redirect = gdk_win32_window_set_override_redirect; |
| 6273 |
impl_class->set_accept_focus = gdk_win32_window_set_accept_focus; |
| 6274 |
impl_class->set_focus_on_map = gdk_win32_window_set_focus_on_map; |
| 6275 |
impl_class->set_icon_list = gdk_win32_window_set_icon_list; |
| 6276 |
impl_class->set_icon_name = gdk_win32_window_set_icon_name; |
| 6277 |
impl_class->iconify = gdk_win32_window_iconify; |
| 6278 |
impl_class->deiconify = gdk_win32_window_deiconify; |
| 6279 |
impl_class->stick = gdk_win32_window_stick; |
| 6280 |
impl_class->unstick = gdk_win32_window_unstick; |
| 6281 |
impl_class->maximize = gdk_win32_window_maximize; |
| 6282 |
impl_class->unmaximize = gdk_win32_window_unmaximize; |
| 6283 |
impl_class->fullscreen = gdk_win32_window_fullscreen; |
| 6284 |
impl_class->unfullscreen = gdk_win32_window_unfullscreen; |
| 6285 |
impl_class->set_keep_above = gdk_win32_window_set_keep_above; |
| 6286 |
impl_class->set_keep_below = gdk_win32_window_set_keep_below; |
| 6287 |
impl_class->get_group = gdk_win32_window_get_group; |
| 6288 |
impl_class->set_group = gdk_win32_window_set_group; |
| 6289 |
impl_class->set_decorations = gdk_win32_window_set_decorations; |
| 6290 |
impl_class->get_decorations = gdk_win32_window_get_decorations; |
| 6291 |
impl_class->set_functions = gdk_win32_window_set_functions; |
| 6292 |
|
| 6293 |
impl_class->set_shadow_width = gdk_win32_window_set_shadow_width; |
| 6294 |
impl_class->begin_resize_drag = gdk_win32_window_begin_resize_drag; |
| 6295 |
impl_class->begin_move_drag = gdk_win32_window_begin_move_drag; |
| 6296 |
impl_class->set_opacity = gdk_win32_window_set_opacity; |
| 6297 |
//impl_class->set_composited = gdk_win32_window_set_composited; |
| 6298 |
impl_class->destroy_notify = gdk_win32_window_destroy_notify; |
| 6299 |
impl_class->get_drag_protocol = _gdk_win32_window_get_drag_protocol; |
| 6300 |
impl_class->register_dnd = _gdk_win32_window_register_dnd; |
| 6301 |
impl_class->drag_begin = _gdk_win32_window_drag_begin; |
| 6302 |
//? impl_class->sync_rendering = _gdk_win32_window_sync_rendering; |
| 6303 |
impl_class->simulate_key = _gdk_win32_window_simulate_key; |
| 6304 |
impl_class->simulate_button = _gdk_win32_window_simulate_button; |
| 6305 |
impl_class->get_property = _gdk_win32_window_get_property; |
| 6306 |
impl_class->change_property = _gdk_win32_window_change_property; |
| 6307 |
impl_class->delete_property = _gdk_win32_window_delete_property; |
| 6308 |
impl_class->create_gl_context = gdk_win32_window_create_gl_context; |
| 6309 |
impl_class->invalidate_for_new_frame = gdk_win32_window_invalidate_for_new_frame; |
| 6310 |
impl_class->get_scale_factor = _gdk_win32_window_get_scale_factor; |
| 6311 |
impl_class->get_unscaled_size = _gdk_win32_window_get_unscaled_size; |
| 6312 |
} |
| 6313 |
|
| 6314 |
HGDIOBJ |
| 6315 |
gdk_win32_window_get_handle (GdkWindow *window) |
| 6316 |
{ |
| 6317 |
/* Try to ensure the window has a native window */ |
| 6318 |
if (!_gdk_window_has_impl (window)) |
| 6319 |
gdk_window_ensure_native (window); |
| 6320 |
|
| 6321 |
if (!GDK_WINDOW_IS_WIN32 (window)) |
| 6322 |
{ |
| 6323 |
g_warning (G_STRLOC " window is not a native Win32 window"); |
| 6324 |
return NULL; |
| 6325 |
} |
| 6326 |
|
| 6327 |
return GDK_WINDOW_HWND (window); |
| 6328 |
} |
| 6329 |
|
| 6330 |
#ifdef GDK_WIN32_ENABLE_EGL |
| 6331 |
EGLSurface |
| 6332 |
_gdk_win32_window_get_egl_surface (GdkWindow *window, |
| 6333 |
EGLConfig config, |
| 6334 |
gboolean is_dummy) |
| 6335 |
{ |
| 6336 |
EGLSurface surface; |
| 6337 |
GdkWin32Display *display = GDK_WIN32_DISPLAY (gdk_window_get_display (window)); |
| 6338 |
GdkWindowImplWin32 *impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 6339 |
|
| 6340 |
if (is_dummy) |
| 6341 |
{ |
| 6342 |
if (impl->egl_dummy_surface == EGL_NO_SURFACE) |
| 6343 |
{ |
| 6344 |
EGLint attribs[] = {EGL_WIDTH, 1, EGL_WIDTH, 1, EGL_NONE}; |
| 6345 |
impl->egl_dummy_surface = eglCreatePbufferSurface (display->egl_disp, |
| 6346 |
config, |
| 6347 |
attribs); |
| 6348 |
} |
| 6349 |
return impl->egl_dummy_surface; |
| 6350 |
} |
| 6351 |
else |
| 6352 |
{ |
| 6353 |
if (impl->egl_surface == EGL_NO_SURFACE) |
| 6354 |
impl->egl_surface = eglCreateWindowSurface (display->egl_disp, |
| 6355 |
config, |
| 6356 |
GDK_WINDOW_HWND (window), |
| 6357 |
NULL); |
| 6358 |
|
| 6359 |
return impl->egl_surface; |
| 6360 |
} |
| 6361 |
|
| 6362 |
} |
| 6363 |
#endif |