Commit Graph

1584 Commits

Author SHA1 Message Date
Chun-wei Fan
ac64d2d910 GDK-Win32: Clean up HiDPI support and WGL a bit
Make _gdk_win32_display_get_monitor_scale_factor() less complex, by:

*  Drop the preceding underscore.

*  Dropping an unused parameter.

*  Using a GdkSurface instead of a HWND, as the HWND that we pass into
   this function might have been taken from a GdkSurface, which are now
   always created with CS_OWNDC.  This means if a GdkSurface was passed
   in, we ensure that we only acquire the DC from the HWND once, and do
   not attempt to call ReleaseDC() on it.

*  Store the HDC that we acquire from the GdkSurface's HWND into the
   surface, and use that as the HDC we need for our GdkGLContext.

*  Drop the gl_hwnd from GdkWin32Display, as that is really should be
   stored in the GdkSurface.

*  For functions that were updated, name GdkWin32Display variables as
   display_win32 and GdkSurface variables as surface, to unify things.

*  Stop calling ReleaseDC() on the HDC that we use for OpenGL, since
   they were acquired from HWND's created with CS_OWNDC.
2021-07-19 18:30:42 +08:00
Chun-wei Fan
49a76257cd gdksurface-win32.c: Create all surfaces with CS_OWNDC
We want to ensure that we have things set up properly for drag surfaces
as well.
2021-07-19 17:36:54 +08:00
Jeremy Tan
2784b03b2d gdkkeys-win32.c: fix initialisation of key_state in update_keymap
It apparently worked by chance in the past, but now causes e.g.
alphanumeric characters to be interpreted as half-width katakana
when using the Japanese IME.
2021-07-09 12:46:49 +08:00
Chun-wei Fan
e35490ba5b gdkdrag-win32.c: Fix drag surface positioning
Determine the root_x and root_y coordinates of the drag surface by
relying on the coordinates of the surface where the drag is being
carried out, plus the coordinates that we receive from the drag event,
which is in-line with what the X11 backend does.

This will prevent the drag surface from being initially drawn at the
correct position, but jumping towards the top-left corner of the screen
shortly afterwards.

The DnD support will still need some more updates to function correctly
on Windows, but at least this is a small improvement.

Fixes issue #3798.
2021-06-18 18:07:50 +08:00
Chun-wei Fan
ba7ec29dc0 gdksurface-win32.c: Fix up popup placement
If we are undergoing a surface move, just apply the next_layout anyways,
even if we are not moving a toplevel surface.

Update the way how we obtain the x and y coordinates of a surface, if it
is a toplevel, apply the x and y coordinates from the results from we
obtained the underlying Win32 HWND, as we did before.  But if it is a
popup, use gdk_win32_surface_get_geometry() to obtain the correct x and
y coordinates to place our popup surface.

Also correct how we compute the shadow dimensions, and the final popup
rectangle as we attempt to layout the popup surface, since GDK-Win32
keeps track of the shadow dimensions in system (unscaled) units, not GDK
units.

Fixes issue #3793.
2021-06-16 16:25:29 +08:00
Chun-wei Fan
85b595bd14 gdksurface-win32.c: Fix formatting for popup functions 2021-06-16 15:02:56 +08:00
Matthias Clasen
fe774c1ad8 Merge branch 'powimod_icon' into 'master'
Load icon from executable on Windows

Closes #3713

See merge request GNOME/gtk!3326
2021-06-05 12:47:08 +00:00
Chun-wei Fan
52d1c0c271 media/gstreamer: Support using GL for video for Windows
Add support to share the WGL context in GDK with the WGL context in GStreamer,
so that we can also use OpenGL in the gstreamer media backend to playback
videos.  For now OpenGL/ES is not supported for this under Windows.

The process of setting this up in Windows is a little bit more involved, as:

*  The OpenGL support in GstGL requires a GL 4.1 Core context, but we may just
   get the GL version from wglCreateContextAttribsARB() that we pass into the
   attributes, which is 3.2 by default.  So, try to ask for a 4.1 Core context
   first if we are asking for anything less.

*  There is only one GstDisplay available for Windows, so we just use
   gst_gl_display_new().

*  We must explicitly tell libepoxy that we are using wglMakeCurrent() outside
   of libepoxy that is being used in GdkGL, otherwise we would end up crashing
   as the GL/WGL function pointers would become invalid.

*  We must also deactivate temporarily the underlying WGL context that was made
   current by gdk_gl_context_make_current() so that when
   gst_gl_display_create_context() calls wglShareLists(), we won't get bitten
   by error 0xaa (resource busy), as some drivers don't handle this well when
   the GL context is current in another thread.

For the last two points we make use of macros defined by the platforms that the
build is done for to help us carry out the necessary tasks as needed.

Thanks to Matthew Waters for the info on integrating GstGL and windowing
toolkits on Windows.
2021-05-24 16:36:40 +08:00
Matthias Clasen
fff2b3c710 gdk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Matthias Clasen
7fe0610b68 introspection: Stop using allow-none
allow-none has been deprecated for a long time
already. Instead use optional and nullable everywhere.
2021-05-20 19:17:49 -04:00
Matthias Clasen
8ba16eb4f1 Documentation fixes
Mostly fixing up indentation of continuation lines,
and other small cleanups.
2021-05-20 19:17:49 -04:00
Chun-wei Fan
6d33e9058c Win32: Add EGLDisplay getter
Like what was done for Wayland and X11, add an API to retrieve the EGLDisplay
if one is being used in place of WGL.
2021-05-12 22:16:56 +08:00
Chun-wei Fan
66e7f3b404 gdkglcontext-win32.c: Fix running with Mesa drivers
Some GL drivers such as Mesa-D3D12 do not allow one to call SetPixelFormat() on
a given HDC if one pixel format has been already set for it, so first check the
HDC with GetPixelFormat() to see whether a pixel format has already been set
with the HDC, and only attempt to acquire the pixel format if one has not been
set.

This will fix running with GL/NGL on Windows using the Mesa drivers.
2021-04-29 12:12:01 +08:00
dparisot
82b11623f4 Load icon from executable on Windows 2021-03-21 15:24:28 +01:00
Chun-wei Fan
38ad068d9b GDK-Win32: Remove extraneous call to _gdk_win32_append_event()
Apparently, by comparing with the other backends, we should not call
_gdk_win32_append_event() after calling gdk_scroll_event_new() but we should
call it after calling gdk_scroll_event_new_discrete(), which was why we didn't
restore the cursor after we scroll using the mouse wheel and didn't manage to
remove the shade that appears after we scrolled to the very top or very bottom.

Also, as suggested by the reporter, use IDC_SIZEALL for the system cursor that
we fall back to if no cursor theme is installed, as with other Windows
programs.

This should really fix issue #3581.
2021-03-17 11:22:23 +08:00
Chun-wei Fan
54b3048584 gdkcursor-win32.c: Add cursor map for all-scroll
This makes sure that we don't have cursors disappearing on Windows upon
scrolling because we can't find a cursor that exists on the system during
a scroll, and unlike GTK-3.x, we do not default to the arrow pointer on GTK4.

Just mimic what we have on X11 and Wayland: the trusty standard arrow pointer.

Fixes issue #3581.
2021-03-15 17:16:33 +08:00
Benjamin Otte
97fad45237 surface: Remove unused gdk_surface_get_unscaled_size()
Also remove unscaled_width/height members in the win32 backend.

Both of those are unused.
2021-03-15 02:56:28 +01:00
Chun-wei Fan
e941e2be7d gdksurface-win32.c: Fix window menu positioning
We ought to get the coordinates of where the window menu should be
displayed using gdk_win32_surface_get_root_coords(), instead of rounding
the position that we obtained with gdk_event_get_position().

Also rename items a bit in the same function, and call
gdk_event_get_event_type() for consistency with the other backends.

Fixes issue #3704.
2021-03-12 18:45:43 +08:00
Matthias Clasen
e62f9e33a1 Merge branch 'gdk-win32-use-window-from-point-for-master' into 'master'
GdkWin32: Fix mouse events in presence of transparent windows on the desktop

Closes #370, #417, and gimp#1082

See merge request GNOME/gtk!2800
2021-03-11 01:09:39 +00:00
Matthias Clasen
e0c48e74bd win32: Apply popup shadow width 2021-02-14 10:52:33 -05:00
Matthias Clasen
5d13bb7aa2 Merge branch 'win32.surface.resize' into 'master'
Some fixes for resizing of GDK/Win32 surfaces

See merge request GNOME/gtk!3144
2021-02-12 14:07:07 +00:00
Emmanuele Bassi
43fd9d16c5 win32: Move from g_memdup() to g_memdup2()
Use `size_t` and `gsize` consistently for the length argument in every
function taking a bytes array and a length.
2021-02-11 14:22:23 +00:00
Matthias Clasen
67877e403f win32: Fix some leaks
My reading of the code is that gdk_drop_new() is not
consuming the content formats it is given, so the caller
must not pass a new reference.

Needs testing on Windows.
2021-02-07 09:41:34 -05:00
Chun-wei Fan
39e136e9b7 Gdk/Win32: Fix resizing surfaces
This attempts to fix the counter-intuitive resizing of surfaces in GTK4 where
the surface grows or shrinks at the right and/or bottom edge when the window
resized from the top and/or left edge(s).

This is not yet perfect as the window stutters upon resizing from the top
and/or left edges, but at least makes resizing more intuitive.
2021-02-02 17:36:32 +08:00
Chun-wei Fan
652b892fc1 gdkwin32surface.[c|h]: Clean up code a bit
Remove the 'resized' member from the GdkWin32Surface structure, as we already
have a structure with a member that keeps track of whether a surface is being
resized, so we can just use that and avoid some confusion in the process
2021-02-02 17:36:32 +08:00
Chun-wei Fan
7b47e3225b GDK/Win32: Remove layered windows usage
In GTK4, we are now defaulting to the OpenGL renderer with the Cairo renderer
only used as a fallback, so there is no point keeping the code paths that use
layered windows as layered windows do not work well with OpenGL nor Vulkan.
2021-01-18 12:48:16 +08:00
Chun-wei Fan
d7d4fed0f3 gdk/win32: Fix window display and resizing
Have an implementation of ->request_layout() and ->compute_size() for the Win32
surface backend so that we can properly display and move and resize the
windows, as we request from the Win32 APIs.

Hxndling Aerosnap properly is mostly done except for snap_up(), which needs to
to be looked at later.
2021-01-11 17:55:25 +08:00
Chun-wei Fan
c2c2635763 gdk/win32: Rename 'margins' to 'shadow'
This improves consistency for the code.
2021-01-11 17:53:56 +08:00
Chun-wei Fan
fb33e83c96 gdkwin32-surface.c: Fix return type
gdk_win32_toplevel_present() should now be returning nothing, not a gboolean.
2021-01-11 17:53:47 +08:00
Chun-wei Fan
291ad17a22 gdksurface-win32.c: Decouple mapped state from surface creation
In line with what is done with the Wayland backend, enable the mapped state
independently as needed from the toplevel surface presentation, and also enable
the mapped state if necessary when presenting the popup surface.
2021-01-11 17:53:38 +08:00
Jonas Ådahl
142f7862ed gdk/toplevellayout: Change API to be about intent, not full state
When being fullscreen, and wanting to unfullscreen but not caring about
whether to go unmaximized or maximized (as this information is lost), if
the GdkToplevelLayout represents the full intended state, we won't be
able to do the right thing.

To avoid this issue, make the GdkToplevelLayout API intend based, where
if one e.g. doesn't call gdk_toplevel_set_maximized() with anything, the
backend will not attempt to change the maximized state.

This means we can also remove the old 'initially_maximized' and
'initially_fullscreen' fields from the private GtkWindow struct, as we
only deal with intents now.
2020-12-16 14:16:08 +01:00
Emmanuele Bassi
99e0929d6c build: Use a consistent style for Meson files 2020-12-15 12:46:59 +00:00
Jonas Ådahl
d2c95a1b13 gdk: Replace 'WITHDRAWN' state with async 'is-mapped' boolean
It was used by all surfaces to track 'is-mapped', but still part of the
GdkToplevelState, and is now replaced with a separate boolean in the
GdkSurface structure.

It also caused issues when a widget was unmapped, and due to that
unmapped a popover which hid its corresponding surface. When this
surface was hidden, it emitted a state change event, which would then go
back into GTK and queue a resize on popover widget, which would travel
back down to the widget that was originally unmapped, causing confusino
when doing future allocations.

To summarize, one should not hide widgets during allocation, and to
avoid this, make this new is-mapped boolean asynchronous when hiding a
surface, meaning the notification event for the changed mapped state
will be emitted in an idle callback. This avoids the above described
reentry issue.
2020-12-07 20:37:30 +01:00
Jonas Ådahl
6ee7535af0 gdk/toplevelsize: Rename 'margin' to 'shadow' and 'shadow_width'
This makes it more consistent with everywhere else.
2020-12-07 20:37:29 +01:00
Jonas Ådahl
42679f2903 gdk: Replace all GDK_CONFIGURE usage with GdkSurface::layout
This removes the GDK_CONFIGURE event and all related functions and data
types; it includes untested changes to the MacOSX, Win32 and Broadway
backends.
2020-12-07 20:37:29 +01:00
Jonas Ådahl
3f96d4b6da gdk: Always get shadow width via GdkToplevelSize
This removes the gdk_surface_set_shadow_width() function and related
vfuncs. The point here is that the shadow width and surface size can now
be communicated to GDK atomically, meaning it's possible to avoid
intermediate stages where the surface size includes the shadow, but
without the shadow width set, or the other way around.
2020-12-07 09:46:39 +01:00
Jonas Ådahl
8c014e63af x11: Remove handling of 'substructure' events
Reading the comment, it seems to be related being a window manager
decoration utility; this is not something GTK4 aims to handle, just drop
support for this.
2020-12-07 09:46:39 +01:00
Matthew Jakeman
710d0620a4 Gdk4/Win32: Correct call to gdk_key_event_new()
The keycode and modifier (state) parameters are in the wrong order
for gdk_key_event_new() in the gdk win32 backend, which causes
key up/down events to be populated incorrectly.
2020-12-02 22:14:27 +00:00
Volker Rümelin
7190a31b5f gdk/win32: fix integer overflow in monitor refresh rate calculation
In gdk/win32/gdkmonitor-win32.c in function
populate_monitor_devices_from_display_config() refresh->Numerator * 1000
overflows for refresh->Numerator > 4294976.

Cast the factor 1000 to UINT64 to prevent the overflow.

Fixes #3394
2020-11-23 21:42:58 +01:00
Luca Bacci
aec87a3514
GdkWin32: Fix mouse events in presence of transparent windows on the desktop
In gdkdevice-win32.c we are interested in knowing which window
receives mouse input at a specific location.

Only WindowFromPoint is the right API for the task, other API's
(such as (Real)ChildWindowFromPoint(Ex)) have shortcomings because
they are really designed for other purposes. For example, only
WindowFromPoint is able to look through transparent layered windows.

So even if we want to find a direct child we have to use
WindowFromPoint and then walk up the hierarchy.

Fixes: #370, #417
See: !2800
2020-11-11 12:46:52 +01:00
Matthias Clasen
7e089664fc win32: Plug listmodel memory leaks
We were leaking references returned from g_list_model_get_item
in some places.
2020-11-10 09:06:37 -05:00
Luca Bacci
eef1097c90
GdkW32: remove klassTEMPSHADOW
Fixes issue #2019
2020-10-27 18:26:45 +01:00
Chun-wei Fan
2cc650ced2 gdk/Win32: Fix mouse pointer capture
Call SetCapture() explcitly for the (new) modal window so that we make the
modal window respond to mouse input, and also call SetCapture() to the parent
of the transient window that we are destroying so that mouse input capture is
returned to the parent window.

This attempts to fix the following:

*  Upon creating a new modal window, the new modal window does not receive
   pointer input unless one switches to another program and back

*  Upon closing a transient window, the parent window that activated the
   transient window does not receive pointer input unless one switches to
   another and back
2020-10-16 10:03:50 +08:00
Руслан Ижбулатов
6a0c181886 GDK W32: Remove stacking functions
Stacking functions enforce non-native stacking behaviour that is
mostly unneeded, and doing so introduces bugs and complicates things.
2020-10-16 10:02:57 +08:00
Руслан Ижбулатов
89286af620 Revert "GDK W32: Use SWP_NOOWNERZORDER everywhere it can be applied"
This reverts commit fc2008f2.

Turns out, we *don't* have code to maintain Z-order. Restacking
code is not doint that, it just enforces a few weird Z-order-related
behaviours.
2020-10-16 10:01:46 +08:00
Chun-wei Fan
bc142b9c43 GDK/Win32: Fix modal window handling
Make sure that we get the state of the modal window properly, and send out the
corresponding notification signals.

This will ensure that we do not try to activate windows that should have become
inactivated due to it opening modal windows and render the program unresponsive
because we are not activating the correct window that is due to receive user
input.
2020-10-16 09:56:42 +08:00
Matthias Clasen
606ab611bd win32: Stop using gdk_surface_new_temp
No need to roundtrip through the frontend to create
one of our own surfaces.
2020-10-07 21:07:40 -04:00
firox263
f0a8c6311e Fix Win32 popup focus when using SSD
Prevents GDK Popups from stealing focus from the parent window when
using Server Side Decorations on win32.

It uses `ShowWindow` and the `SW_SHOWNOACTIVATE` flag.
2020-10-06 22:37:35 +13:00
Chun-wei Fan
52ba70d549 gdksurface-win32.c: Fix display of CSD windows
Since the changes to GDK to use surface subtypes, CSD windows were
broken because we did not set the window styles properly.  Fix this by
first acquiring whether decorations are used by the GtkWindow, and based
on that result we set the decorations that we want to use accordingly
and so apply them.

Thanks to Matt Jakeman for investigating into the issue and providing
pointers to a proposed fix.

Fixes issue #3157, besides the part where window sizes are not correct
since that is likely caused a separate issue.
2020-09-15 15:56:36 +08:00
Chun-wei Fan
02aec7f5f4 gdkevents-win32.c: Clean up WM_ACTIVATE handling a bit
We can group some things together, to make things a little bit more clear
2020-09-15 15:53:34 +08:00