Commit Graph

1146 Commits

Author SHA1 Message Date
Mohammed Sadiq
fd4bfd5050 build: Fix compiler warnings 2018-06-11 21:12:41 +05:30
Carlos Garnacho
d94ac2ed61 Merge branch 'issue792' into 'master'
wayland: check native surface for crossing events

Closes #792

See merge request GNOME/gtk!148
2018-05-22 11:10:26 +00:00
Jonas Ådahl
a5d000cb5c wayland: Fix restarting cursor animation
When an animated cursor was set and the previous cursor animation delay
happened to be the same, we wouldn't restart the animation timeout and
just return G_SOURCE_CONTINUE assuming the timer would continue. This
assumption is however only valid if the function was called from the
timeout, which is not the case.

Instead also arm the timer also if there is no previous timer active.
2018-05-09 22:17:03 +02:00
Olivier Fourdan
d3885e92a7 wayland: check native surface for crossing events
gdk_wayland_*_grab()/ungrab() would emit crossing events which translate
as focus_in/focus_out events for keyboard.

However, the ungrab() functions compare the native toplevel as this is
what gets the Wayland pointer enter/leave events with the grab surface,
so if the grab is issued on a child gdk surface, those won't match and
we would emit more focus_out events than focus_in.

This means that a widget such as spice-gtk which issues a keyboard grab
whenever the pointer enters the surface and releases the grab when it
leaves the surface would get uneven numbers of focus_in/focus_out
events.

Also, gdk_wayland_seat_ungrab() would not emit crossing events for
keyboard devices, whereas gdk_wayland_device_ungrab() does, which adds
even more potential discrepancies between focus_in/focus_out events.

To solve this problem, introduce two new helper functions which check
the relevant native surfaces to emit crossing events when needed that
get called evenly from both gdk_wayland_seat_grab()/ungrab() and gdk
_wayland_device_grab()/ungrab() APIs.

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=780422
Closes https://gitlab.gnome.org/GNOME/gtk/issues/792
2018-05-09 17:30:34 +02:00
Benjamin Otte
34d1ebc562 dnd: Make "formats" a construct-only property
... and hide the member variable inside the DragContextPrivate.
2018-05-07 18:55:09 +02:00
Benjamin Otte
80f5fd8435 wayland: Remove stray if
Leftover from d056be4ea2.

I need more sleep when I need to fixup the fixups of my fixups now.
2018-05-07 18:55:09 +02:00
Benjamin Otte
d056be4ea2 wayland: Fix memleak
7f8a8f221d forgot to free the data offer
passed to it.
2018-05-07 16:28:50 +02:00
Benjamin Otte
7f8a8f221d wayland: Redo DND offer handling
Instead of tracking offers in GdkWaylandSelection objects, track the
pending offer in the GdkWaylandSeat and pass it to the GdkDragContext
once we get an enter event.
2018-05-06 02:10:20 +02:00
Matthias Clasen
45db4a5550 Merge branch 'wip/xdg-shell' into 'master'
xdg shell (stable)

See merge request GNOME/gtk!35
2018-05-04 00:43:01 +00:00
Benjamin Otte
8366ef71c0 dnd: Remove gdk_drop_reply()
It was only necessary for Motif DND, and we don't support that anymore.
2018-05-03 01:31:40 +02:00
Benjamin Otte
fb53568c04 gdk: Remove gdk_drag_grop_succeeded()
It's unused and most backends don't implement it.
2018-05-03 01:31:39 +02:00
Ting-Wei Lan
7fed0b74ed wayland: Use dev/evdev/input.h on FreeBSD
The header linux/input.h used by GDK is specific to Linux. It is
possible to get a few Linux headers on FreeBSD by installing v4l_compat,
but it is usually better to use the one shipped with FreeBSD.

We prefer dev/evdev/input.h to linux/input.h here, so it will always use
dev/evdev/input.h on FreeBSD regardless of v4l_compat.

https://svnweb.freebsd.org/changeset/ports/465644
2018-05-01 22:28:57 +08:00
Jonas Ådahl
5f19421bc9 wayland: Various whitespace cleanups
Broke up a long line, added an empty one, indented another one, and re-aligned
a large amount of function parameter names that got misaligned in some past
refactoring.

https://bugzilla.gnome.org/show_bug.cgi?id=791939
2018-05-01 13:39:42 +02:00
Jonas Ådahl
a40923b03a wayland: Add support for xdg-shell stable
This commit adds support the stable version of the xdg-shell protocol.
Support for the last version of the unstable series is left intact, but
will not receive new features.

The stable version is prioritized above the older version.

https://bugzilla.gnome.org/show_bug.cgi?id=791939
2018-05-01 13:36:38 +02:00
Matthias Clasen
3684b72121 Misc documentation fixes
Close some gaps in gdk docs.
2018-04-28 22:34:14 -04:00
Benjamin Otte
4aaeb7de19 dnd: Make GdkDragContext::device a (construct-only) property
Also remove gdk_drag_context_set_device() and insist on backends using
the property.
2018-04-27 14:32:28 +02:00
Benjamin Otte
a86359af2b wayland: Create drop contexts on demand
Instead of creating and reusing the same one from start to finish.
2018-04-27 14:32:28 +02:00
Benjamin Otte
ae7a677346 cairocontext: Remove fallback implementations
Now that all Cairo contexts are ported to managing cairo surfaces
themselves, the old fallback code that didi the managing is no longer
needed.

Also clarify the behavior of gdk_cairo_context_cairo_create() wrt the
vfunc by doing the early exit and the clipping outside of it.
2018-04-24 23:24:55 +02:00
Benjamin Otte
83ea0b3714 drawcontext: Only pass the region that matters
We used to pass 2 regions to GdkDrawCotnext.end_frame() but code was
confusing what they meant. So we now don't do that anymore and only pass
the region that matters: The frame region.
2018-04-24 23:16:58 +02:00
Benjamin Otte
fd686afeb2 drawcontext: Add gdk_draw_context_in_frame() API
This makes the previous gdk_draw_context_is_drawing() function public
under a new name.

I decided against the old name because we use the term "frame" for a
drawing operation, so I wanted to have this boolean flag reuse the term.
2018-04-24 23:16:58 +02:00
Benjamin Otte
4aac0760b3 wayland: Rewrite Cairo rendering
Also, split it into its own file - which was the original reason for
looking at this code, the rewrite was an unintentional side effect.

This changes the context to create surfaces on demand.
So whenever the compositor holds onto a surface while GDK wants to
render, it just creates a new surface. If the compositor releases
surfaces, we will retain one for the next frame to be rendered, but free
all extra ones.
This way, we should get to a stage where we have exactly as many
surfaces as needed and never allocate/free any.
2018-04-24 23:16:58 +02:00
Benjamin Otte
813e9c95fb gdk: Add Cairo context implementations for all backends
And make the GdkCairoContext as abstract.

The idea of this and thje following commits is to get rid of all
Cairo code in gdksurface.c (and $backend/gdksurface-$backend.c)
by moving that code into the Cairo context files.
In particular, the GdkSurfaceClass.begin_frame/end_frame()
functions (which are currently exclusively used by the Cairo code
should end up being moved to GdkDrawContextClass.begin/end_frame().

This has multiple benefits:

1. It unifies code between the different drawing contexts.
   GL lives in GLContext, Vulkan in VulkanContext and Cairo in
   CairoContext. In turn, this makes it way easier to reason about
   what's going on in surface-specific code. Currently pretty much
   all backends do things wrong when they want to sync to drawing
   or to the frame clock.

2. It makes the API of GdkSurface smaller. No drawing code (apart
   from creating the contexts) needs to remain.

3. It confines Cairo to the Drawcontext, thereby making it way
   more obvious when backends are still using it in situations
   where it may now conflict with OpenGL (like when doing the dnd
   failed animation or in the APIs that I'm removing in this
   branch).

4. We have 2 very different types of Cairo contexts: The X/win32
   model, where we have a natively supported Cairo backend but do
   double buffering ourselves and use similar surfaces and the
   Wayland/Broadway model where we use image surfaces without any
   Cairo backend support and have to submit the buffers manually.
   By not sharing code between those 2 versions, we can make the
   actual code way smaller. We also get around the need to create
   1x1 image surfaces in the Wayland backend where we pretend
   there's a native Cairo surface.
2018-04-24 23:16:12 +02:00
Emmanuele Bassi
fc57d3b5a3 wayland: Allow a NULL inhibitors hash table
The shortcuts inhibitors hash table is created when we create a
GdkWaylandWindow implementation for a GdkWindow, and it's destroyed once
we finalize the instance. The fake "root" window we create for the
Wayland display does not have a backing native window, so the shortcuts
inhibitors hash table is set to NULL; this causes a critical error
message when calling g_hash_table_destroy() on it. The finalization of
the root window happens when we close a display connection.

We should use g_clear_pointer(), instead, as it's NULL safe.

Without this change, the displayclose test fails, as all warnings are
considered fatal.
2018-04-23 10:57:07 +01:00
Benjamin Otte
fc6018f192 wayland: Don't freeze the frame clock too early
We can't freeze the frame clock on commit, but only after-paint,
otherwise the frameclock will resume in the paint stage.

So freeze the frame clock at the end of the frame if we are waiting for
a frame callback.

Note; The diff is only lage because of indentation changes due to
avoiding early returns in favor of a branch.
2018-04-13 02:16:10 +02:00
Benjamin Otte
4aab8e970b gdk: Remove gdk_surface_create_similar_image_surface()
It's unused.
2018-04-12 14:04:33 +02:00
Emmanuele Bassi
a2a99d27c9 Simplify the Wayland code generation
Instead of going through an ancillary script to strip away the
`WL_EXPORT` annotation from the generated code, we should bump up the
required version of Wayland, and use the `private-code` argument for
wayland-scanner, which does the right thing for us.
2018-04-11 15:06:43 +01:00
Benjamin Otte
adc0159bdb wayland: Factor out frame timings request code
Also call the code everywhere we draw and not just with Cairo.
2018-04-10 15:13:38 +02:00
Benjamin Otte
bb8f6f87ae glcontext: Store the buffer age regions in the GL context
That way, we can store the right region there: The actual painted area
instead of the exposed area (which is way too small).

Also, the GL context is the only user of this data, so storing it there
seems way smarter.
2018-04-09 01:00:31 +02:00
Matthias Clasen
448d2502d9 Merge branch 'bz773274' into 'master'
wayland: Don't paint if the window is unmapped

See merge request GNOME/gtk!32
2018-03-25 20:44:44 +00:00
Benjamin Otte
cb4ec6f384 gdk: Remove GdkSurfaceImpl::shape_combine_region vfunc
... and all the implementations.

Input shapes still exist.
2018-03-21 23:28:26 +01:00
Matthias Clasen
877b48579e Merge branch 'wip/sync-pre-swap-buffers' into 'master'
Synchronize wl_surface state before wl_surface_commit

See merge request GNOME/gtk!75
2018-03-21 11:40:55 +00:00
Alexander Larsson
8d05fcd35c Fix up indentation after GdkSurface rename
This fixes up a lot of the indentation issues from the
rename of windows to surfaces, at least the ones in the headers
and many others.
2018-03-21 09:06:31 +01:00
Jonas Ådahl
7e102f8879 wayland/vulkancontext: Sync surface state before vkQueuePresentKHR
A side effect of vkQueuePresentKHR is the Vulkan implementation calling
wl_surface_commit() on the corresponding Wayland surface. Thus, before
this, we must synchronize the surface state (e.g. opaque region, window
geometry, etc) that changed since last time. Prior to this commit this
was done after calling vkQueuePresentKHR(), causing the surface state to
always correspond to the previous buffer state. As of this commit this
is now done before calling vkQueuePresentKHR(), thus before
wl_surface_commit().
2018-03-21 14:14:32 +08:00
Jonas Ådahl
1d5d46ff29 wayland/glcontext: Sync surface state before swapping buffers
A side effect of eglSwapBuffers* is the EGL implementation calling
wl_surface_commit() on the corresponding Wayland surface. Thus, before
swapping buffers, we must synchronize the surface state (e.g. opaque
region, window geometry, etc) that changed since the last buffer swap.
Prior to this commit, this was done after eglSwapBuffers*, causing the
surface state to always correspond to the previous buffer state. As of
this commit this is now done before swapping the buffers, thus before
wl_surface_commit().
2018-03-21 14:14:20 +08:00
Benjamin Otte
2a4ffd4a59 surface: Simplify gdk_surface_invalidate_region()
Remove duplicate functions and unused arguments.

Functionality is identical otherwise.
2018-03-21 04:10:07 +01:00
Benjamin Otte
8202f333ea surface: Stop tracking clip region
It's not needed because we're not using it for anything anymore now that
client-side surfaces aren't drawn anymore.
2018-03-21 04:10:07 +01:00
Olivier Fourdan
77a5d00047 wayland: Drop cairo surfaces when withdrawing
If a surface is unmapped by the client while gdk is processing updates,
(for example Firefox un-mapping its window on Expose events), the
windowing backend resources might be lost (for example with Wayland)
which can cause a crash in end_paint().

Make sure we drop the cairo surfaces as well when hiding the surface,
that will avoid the crash in gdk_surface_impl_wayland_end_paint() when
trying to attach the staging cairo surface to a released wl_surface,
these will be recreated when needed when the surface becomes visible
again and there is no need to keep such buffers around for a surface
which is not visible anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=793062
2018-03-20 18:49:56 +01:00
Alexander Larsson
63e060a21d GtkWidget: Start renaming widget->window
This is an automated change doing these command:

git sed -f g gtk_widget_set_has_window gtk_widget_set_has_surface
git sed -f g gtk_widget_get_has_window gtk_widget_get_has_surface
git sed -f g gtk_widget_set_parent_window gtk_widget_set_parent_surface
git sed -f g gtk_widget_get_parent_window gtk_widget_get_parent_surface
git sed -f g gtk_widget_set_window gtk_widget_set_surface
git sed -f g gtk_widget_get_window gtk_widget_get_surface
git sed -f g gtk_widget_register_window gtk_widget_register_surface
git sed -f g gtk_widget_unregister_window gtk_widget_unregister_surface

git checkout NEWS*
2018-03-20 15:21:12 +01:00
Alexander Larsson
3dce0dcca7 GdkSurface: Rename lots of stuff from window->surface
Mostly these are internal things, but the major public change is
that event.window is now event.surface.
2018-03-20 15:14:10 +01:00
Alexander Larsson
9a7e721181 GdkSurface: Rename various functions and variables
This is an automatic rename of various things related
to the window->surface rename.

Public symbols changed by this is:
 GDK_MODE_WINDOW
 gdk_device_get_window_at_position
 gdk_device_get_window_at_position_double
 gdk_device_get_last_event_window
 gdk_display_get_monitor_at_window
 gdk_drag_context_get_source_window
 gdk_drag_context_get_dest_window
 gdk_drag_context_get_drag_window
 gdk_draw_context_get_window
 gdk_drawing_context_get_window
 gdk_gl_context_get_window
 gdk_synthesize_window_state
 gdk_surface_get_window_type
 gdk_x11_display_set_window_scale
 gsk_renderer_new_for_window
 gsk_renderer_get_window
 gtk_text_view_buffer_to_window_coords
 gtk_tree_view_convert_widget_to_bin_window_coords
 gtk_tree_view_convert_tree_to_bin_window_coords

The commands that generated this are:

git sed -f g "GDK window" "GDK surface"
git sed -f g window_impl surface_impl
(cd gdk; git sed -f g impl_window impl_surface)
git sed -f g WINDOW_IMPL SURFACE_IMPL
git sed -f g GDK_MODE_WINDOW GDK_MODE_SURFACE
git sed -f g gdk_draw_context_get_window gdk_draw_context_get_surface
git sed -f g gdk_drawing_context_get_window gdk_drawing_context_get_surface
git sed -f g gdk_gl_context_get_window gdk_gl_context_get_surface
git sed -f g gsk_renderer_get_window gsk_renderer_get_surface
git sed -f g gsk_renderer_new_for_window gsk_renderer_new_for_surface

(cd gdk; git sed -f g window_type surface_type)
git sed -f g gdk_surface_get_window_type gdk_surface_get_surface_type

git sed -f g window_at_position surface_at_position
git sed -f g event_window event_surface
git sed -f g window_coord surface_coord
git sed -f g window_state surface_state
git sed -f g window_cursor surface_cursor
git sed -f g window_scale surface_scale
git sed -f g window_events surface_events
git sed -f g monitor_at_window monitor_at_surface
git sed -f g window_under_pointer surface_under_pointer
(cd gdk; git sed -f g for_window for_surface)
git sed -f g window_anchor surface_anchor
git sed -f g WINDOW_IS_TOPLEVEL SURFACE_IS_TOPLEVEL
git sed -f g native_window native_surface
git sed -f g source_window source_surface
git sed -f g dest_window dest_surface
git sed -f g drag_window drag_surface
git sed -f g input_window input_surface

git checkout NEWS* po-properties po docs/reference/gtk/migrating-3to4.xml
2018-03-20 12:05:26 +01:00
Alexander Larsson
890080ebf7 GdkWindow -> GdkSurface: File renames
Rename all *window.[ch] source files.

This is an automatic operation, done by the following commands:

for i in $(git ls-files gdk | grep window); do
    git mv $i $(echo $i | sed s/window/surface/);
    git sed -f g $(basename $i) $(basename $i | sed s/window/surface/) ;
done

git checkout NEWS* po-properties po
2018-03-20 11:46:11 +01:00
Alexander Larsson
391727bd0d GdkWindow -> GdkSurface initial type rename
This renames the GdkWindow class and related classes (impl, backend
subclasses) to surface. Additionally it renames related types:
GdkWindowAttr, GdkWindowPaint, GdkWindowWindowClass, GdkWindowType,
GdkWindowTypeHint, GdkWindowHints, GdkWindowState, GdkWindowEdge

This is an automatic conversion using the below commands:

git sed -f g GdkWindowWindowClass GdkSurfaceSurfaceClass

git sed -f g GdkWindow GdkSurface
git sed -f g "gdk_window\([ _\(\),;]\|$\)" "gdk_surface\1" # Avoid hitting gdk_windowing
git sed -f g "GDK_WINDOW\([ _\(]\|$\)" "GDK_SURFACE\1" # Avoid hitting GDK_WINDOWING
git sed "GDK_\([A-Z]*\)IS_WINDOW\([_ (]\|$\)" "GDK_\1IS_SURFACE\2"
git sed GDK_TYPE_WINDOW GDK_TYPE_SURFACE
git sed -f g GdkPointerWindowInfo GdkPointerSurfaceInfo

git sed -f g "BROADWAY_WINDOW" "BROADWAY_SURFACE"
git sed -f g "broadway_window" "broadway_surface"
git sed -f g "BroadwayWindow" "BroadwaySurface"
git sed -f g "WAYLAND_WINDOW" "WAYLAND_SURFACE"
git sed -f g "wayland_window" "wayland_surface"
git sed -f g "WaylandWindow" "WaylandSurface"
git sed -f g "X11_WINDOW" "X11_SURFACE"
git sed -f g "x11_window" "x11_surface"
git sed -f g "X11Window" "X11Surface"
git sed -f g "WIN32_WINDOW" "WIN32_SURFACE"
git sed -f g "win32_window" "win32_surface"
git sed -f g "Win32Window" "Win32Surface"
git sed -f g "QUARTZ_WINDOW" "QUARTZ_SURFACE"
git sed -f g "quartz_window" "quartz_surface"
git sed -f g "QuartzWindow" "QuartzSurface"

git checkout NEWS* po-properties
2018-03-20 11:40:08 +01:00
Carlos Garnacho
f22403a317 gdk/wayland: Use GDK_AVAILABLE_IN_ALL
GDK_AVAILABLE_IN_4_0 makes it unavailable till 4.0, but we want
it now.
2018-02-16 19:36:41 +01:00
Carlos Garnacho
3b568fbe77 gdk/wayland: Add GdkDisplay call to query available globals
The internal known_globals hashtable is used to carry accounting for
interfaces that depend on others (as ordering is not guaranteed), extend
its usage so it also keeps track of unimplemented interfaces (here at
least).

The API call will then use this to allow querying the globals offered by
the compositor, it will be useful to determine whether we can use
text-input protocols or should fallback to other IMs.
2018-02-13 15:47:57 +01:00
Matthias Clasen
4c150d8eb5 The big versioning cleanup
Remove all the old 2.x and 3.x version annotations.
GTK+ 4 is a new start, and from the perspective of a
GTK+ 4 developer all these APIs have been around since
the beginning.
2018-02-06 01:16:32 -05:00
Emmanuele Bassi
bfcb978079 Drop the last mentions of motion hint events
The GDK_POINTER_MOTION_HINT_MASK enumeration value is gone, but we're
still keeping around the "is_hint" field in GdkEventMotion, even though
every backend sets it to `false` — except for the core X11 device
manager.
2018-02-05 14:00:51 +00:00
Timm Bäder
cd6408b47a gdk: fix a format string warning 2018-02-04 15:48:47 +01:00
Emmanuele Bassi
2cbe094b91 Allow binding GdkContentFormatsBuilder
GdkContentFormatsBuilder is currently not introspectable, as it does not
have a GType. We can turn it into a boxed type, but we need to implement
memory management for it.

The current gdk_content_formats_builder_free() function returns a newly
constructed value, so we cannot use it as a GBoxedFreeFunc; additionally
copying a GdkContentFormatsBuilder contents would make it a bit odd, as
you could get multiple identical GdkContentFormats out of the copies.

A simple approach is to model the GdkContentFormatsBuilder API to follow
the GBytes one: use reference counting for memory management, and have
a function to release a reference, return a GdkContentFormats, and reset
the GdkContentFormatsBuilder state.

For language bindings, we can provide a get_formats() function that
returns the GdkContentFormats instance and resets the builder instance,
leaving the reference count untouched.

For C convenience we can keep gdk_content_formats_builder_free(), and
make it a wrapper around gdk_content_formats_builder_get_formats(), with
the guarantee that it'll free the builder instance regardless of its
current reference count.

https://bugzilla.gnome.org/show_bug.cgi?id=793097
https://blogs.gnome.org/otte/2018/02/03/builders/
2018-02-03 16:24:13 +01:00
Emmanuele Bassi
888dfe499d Drop the Big GDK Lock
GDK has a lock to mark critical sections inside the backends.
Additionally, code that would re-enter into the GTK main loop was
supposed to hold the lock.

Back in the Good Old Days™ this was guaranteed to kind of work only on
the X11 backend, and would cause a neat explosion on any other GDK
backend.

During GTK+ 3.x we deprecated the API to enter and leave the critical
sections, and now we can remove all the internal uses of the lock, since
external API that uses GTK+ 4.x won't be able to hold the GDK lock.

https://bugzilla.gnome.org/show_bug.cgi?id=793124
2018-02-03 12:07:10 +01:00
Emmanuele Bassi
c655759cef Replace gdk_threads_add_timeout* with g_timeout_add()
The main GDK thread lock is not portable and deprecated.

The only reason why gdk_threads_add_timeout() and
gdk_threads_add_timeout_full() exist is to allow invoking a callback
with the GDK lock held, in case 3rd party libraries still use the
deprecated gdk_threads_enter()/gdk_threads_leave() API.

Since we're removing the GDK lock, and we're releasing a new major API,
such code cannot exist any more; this means we can use the GLib API for
installing timeout callbacks.

https://bugzilla.gnome.org/show_bug.cgi?id=793124
2018-02-03 12:06:58 +01:00