Commit Graph

1672 Commits

Author SHA1 Message Date
Timm Bäder
94d3fd84b5 window: Remove unused private function 2020-05-05 08:20:10 +02:00
Matthias Clasen
9a65ed9ada window: Derive from GtkWidget
We want to remove GtkBin and GtkContainer as they don't
provide much useful functionality anymore. This requires
us to move get_request_mode and compute_expand down.

Update the accessible implementation to match, remove
remnants of container implementations in GtkWindow
subclasses, and fix livecycle issues around destroy
vs dispose in GtkAssistant.

After this commit, using gtk_container_add on window
subclasses is not allowed anymore, but adding childing
with <child> in ui files still works.

See #2681
2020-05-04 22:53:08 -04:00
Matthias Clasen
b9b1bf85e1 window: Add a child property 2020-05-04 22:53:07 -04:00
Alexander Mikhaylenko
c2e4e1af73 headerbar: Remove user-settable title
Use window title, or custom title widget if it's set. Remove 'title'
property.

Update demos and tests to set the title on the window instead of
headerbar.
2020-05-01 19:48:05 +05:00
Alexander Mikhaylenko
43a453e465 headerbar: Remove has-subtitle property
Subtitle will go too in the next commit, but has-subtitle goes first as
it's broken right now anyway.
2020-05-01 19:48:05 +05:00
Emmanuele Bassi
2a11f5f889 Use attributes instead of element-type annotation
The `element-type` annotation is for GList and GSList only, and turns
out adding support for GListModel in gobject-introspection breaks Vala
and the GIR for GIO.

Instead of using `element-type`, we can use the `attributes` annotation,
which is ignored by code generators based on the GIR data.
2020-04-28 13:31:29 +01:00
Matthias Clasen
637890517b Move the idle sizer to the gtkroot.c
This is needed since we already have a second GtkRoot
implementation with GtkDragIcon, and DND is causing
critical warnings due to this.
2020-04-25 21:03:57 -04:00
Carlos Garnacho
d104efe06e gtkwindow: Correct device check
This function to revoke implicit grabs may be called with a NULL
device, which means all devices should be revoked. Fix the check
so this actually happens.

Fixes implicit grabs (maybe) being unset in result to a GTK grab.
2020-04-24 23:04:27 +02:00
Benjamin Otte
389575ee18 Merge branch 'wip/exalm/window-headerbar' into 'master'
First steps for #2242

See merge request GNOME/gtk!1739
2020-04-23 15:26:30 +00:00
Alexander Mikhaylenko
7c4694ca3c window: Stop listening to headerbar title changes
Remove another dependency.
2020-04-23 19:26:10 +05:00
Alexander Mikhaylenko
610d5794ac headerbar: Update window buttons automatically
Update the layout when any of the following properties changes:
 * modal
 * transient-for
 * resizable
 * deletable

Stop updating it from GtkWindow, make that function static.
2020-04-23 19:26:10 +05:00
Matthias Clasen
b0f2cd02ad window: Tweak visible focus behavior
Only turn on visible focus when a key event actually leads
to a change in focus location (ie, 'keynav').

Make the visible focus disappear after 5 seconds of no
keyboard interaction, to avoid permanent focus ring
distraction.

As an extra bonus, make it so that we make the focus
visible while the Alt key is pressed. This gives us
a 'find my focus!' shortcut, and goes well with the
prexisting use of Alt for finding mnemonics.

Discussed in: #2644
2020-04-23 09:33:26 -04:00
Matthias Clasen
94906d076a Drop gtk_widget_reset_style
There was a single call left that should not be necessary.
Also drop no longer used attached-window functionality.
2020-04-22 19:30:48 -04:00
Matthias Clasen
129b8bb7f1 window: Use gtk_system_setting_change
Propagate GTK_SYSTEM_SETTING_DISPLAY when the display
of the window changes.
2020-04-22 19:29:15 -04:00
Alexander Mikhaylenko
451c3279ee window: Introduce actions for window buttons
Add the following actions:
 * window.close
 * window.toggle-maximize
 * window.minimize

Ensure they are disabled when not appropriate, such as for modal windows.

Use them in GtkHeaderBar.
2020-04-22 23:01:12 +05:00
Alexander Mikhaylenko
016eac0645 header-bar: Track window icon changes
Listen to icon-name changes if it's in a GtkWindow. This allows to remove a
special case for headerbar-as-titlebar from GtkWindow.
2020-04-22 23:01:12 +05:00
Alexander Mikhaylenko
cead405831 header-bar: Don't assume there's only one icon
Instead of tracking the titlebar icon widget, and updating it when the icon
changes, update the window buttons completely.
2020-04-22 23:01:12 +05:00
Matthias Clasen
2ddff872cd css: Drop the -gtk-icon-theme property
We want to always use the current icon theme, and only
have the minimum amount of custom properties.
2020-04-22 12:35:30 -04:00
Matthias Clasen
98611735ec Stop using the -gtk-icon-theme style property
We want to just use the current icon theme, always.
2020-04-22 12:35:22 -04:00
Alexander Mikhaylenko
2240eb5c99 header-bar: Stop showing application menu
The application menu isn't particular relevant anymore, and the support for
showing fallback appmenu as a headerbar icon is one of the things tying
GtkWindow to GtkHeaderBar.

Remove support for "menu" window decoration element completely, update
GtkHeaderBar docs.
2020-04-22 21:30:19 +05:00
Matthias Clasen
b55195fa2e Move the idle sizer to GtkWindow
This was only living in gtkcontainer.c for historic
reasons. Move it closer to where it belongs, and
rename it from 'idle' to 'layout', since it is
really about the layout phase of the frame clock,
nowadays.
2020-04-20 16:30:45 -04:00
Emmanuele Bassi
f28aa1ba02 Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.

The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.

The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 19:54:02 +01:00
Matthias Clasen
54b99d281b Add a focus-within state
This is used for widgets that contain the focus widget,
reserving the focused state for the focus location itself.

This aligns our focus state handling with
https://www.w3.org/TR/selectors-4/
2020-04-16 12:31:01 -04:00
Matthias Clasen
dbd578eaef window: Don't set is-active twice
We are listening to focus change events for this
no need to duplicate the work in ::state-changed.
2020-04-15 17:08:15 -04:00
Matthias Clasen
031b248c20 window: Fix setting :is-active
We want to listen to focus events from the windowing
system here, relying on crossing events for this doesn't
work.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2612
2020-04-15 14:43:00 -04:00
Matthias Clasen
08fbd012ec window: Make resize cursors work for modal dialogs
We were inadvertedly not letting the grab_widget determine
a cursor. This was showing up as resize cursors not appearing.
2020-04-12 22:18:50 -04:00
Matthias Clasen
1efa781a19 window: Cosmetic cleanup
Use a convenience function to get the current event time.
2020-04-12 17:32:13 -04:00
Matthias Clasen
0ee58e9ef4 gtk: Port widgets away from gtk_get_current_ apis
Use the event controller equivalents where needed.
This commit covers the simple cases.
2020-04-11 17:29:27 -04:00
Matthias Clasen
6b9ac1043b Document actions 2020-04-11 10:07:31 -04:00
Matthias Clasen
7379c34a39 window: Respect widget cursors
gtk_widget_set_cursor can be used on a GtkWindow; we
should not blow away the result when temporarily installing
resize cursors.
2020-04-10 14:36:55 -04:00
Matthias Clasen
72ae6daa1e Move focus to the parent if a popover is dismissed
This is better than just dropping focus altogether,
and is expected behavior in most cases.
2020-04-09 18:26:31 -04:00
Matthias Clasen
2a18f2150d window: Make set_focus equal to grab_focus
Make gtk_window_set_focus call gtk_widget_grab_focus internally.
This means that set_focus can now end up putting the focus on
a child of the passed-in widget, and makes the focus-widget
property work for setting initial focus to (the child of) an
entry in a ui file.
2020-04-09 17:50:28 -04:00
Matthias Clasen
a65fd81106 root: Reorganize focus handling
Make :focus-widget a GtkWindow property and add vfuncs
to the GtkRoot interface instead of the property.
2020-04-09 17:50:28 -04:00
Matthias Clasen
b02db72e17 Rename GDK_MOD1_MASK to GDK_ALT_MASK
We've hardcoded Mod1 = Alt for a long time, there is
no need to keep the confusing naming around anymore.
2020-04-06 01:40:49 -04:00
Timm Bäder
046190cb8a window: Don't leak toplevel layout 2020-04-03 07:37:54 +02:00
Matthias Clasen
1f8e633fff window: tie focus to surface state changes
We don't get a focus-out on the event controller, when
the surface is losing keyboard focus, since we are not
moving our focus to some other widget, so we are never
unsetting the mnemonics-visible property. Do that in
response to surface state changes instead.
2020-04-02 17:21:01 -04:00
Matthias Clasen
5432f73095 window: Fix residual resizing issues
After the GdkToplevel split, GtkWindow occasionally
forgets its minimum size. Fix this by keeping a GdkToplevelLayout
around and reusing it.
2020-03-31 13:07:44 -04:00
Matthias Clasen
de31bb59a1 window: Remove initial-focus leftovers
We removed the way to set initial_focus a year ago,
time to get rid of the leftovers.
2020-03-29 23:39:54 -04:00
Matthias Clasen
fd95cc56b1 window: Remove GtkKeyHash remnants
It is not used anymore.
2020-03-25 23:14:45 -04:00
Benjamin Otte
bb4fbe3d8f accels: Remove GtkAccelGroup 2020-03-25 23:14:44 -04:00
Benjamin Otte
daa7d9072d application: Replace accelerator handling with shortcuts
API remains the same, but activation is now done via a
shortcutcontroller.

The code uses a controller with global scope so that the
shortcuts are managed with all the other global shortcuts.
2020-03-25 23:14:28 -04:00
Benjamin Otte
92e20deca1 shortcut: Change the API for creating shortcuts
When creating shortcuts, there almost always are a trigger and an action
available for use. So make gtk_shortcut_new() take those as arguments.

Also add gtk_shortcut_new_with_arguments() so people can easily pass
those in, too.
2020-03-25 23:14:27 -04:00
Benjamin Otte
cd0332aad5 shortcut: Add GtkShortcutAction
Similar to GtkShortcutTrigger, GtkShortCutAction provides all the
different ways to activate a shortcut.

So far, these different ways are supported:

 - do nothing
 - Call a user-provided callback
 - Call gtk_widget_activate()
 - Call gtk_widget_mnemonic_activate()
 - Emit an action signal
 - Activate an action from the widget's action muxer
2020-03-25 23:14:27 -04:00
Emmanuele Bassi
2c62cde780 window: Remove all old mnemonic handling API 2020-03-25 23:14:27 -04:00
Emmanuele Bassi
aab10ea43b Add GtkShortcutManager
This adds an interface for taking care of shortcut controllers with
managed scope.

Only GtkWindow currently implements this interface, so we need to ensure
that we check if any top-level widget we reach is a shortcuts manager
before we call into it.
2020-03-25 23:14:27 -04:00
Benjamin Otte
0b7e74318b window: Put F10 accelerator into its own shortcut controller
So instead of relying on gtk_window_activate_key(), it's now using
proper infrastructure.
2020-03-25 23:14:27 -04:00
Benjamin Otte
e398f63bf6 window: Get rid of public APIs that shouldn't be
Event controllers should have replaced all of them.
And if they haven't, apps need to fix their code (I'm
looking at you Gimp).
2020-03-25 23:14:27 -04:00
Benjamin Otte
81fa63260e trigger: Add an alternative trigger
And use it.

I just added it to GtkWidget just to show that I can.
The real reason I want it is for gamepad/joystick triggers
in games, so that it becomes possible to select 2 different
triggers (gamepad and keyboard) for the same shortcut.
2020-03-25 22:36:03 -04:00
Benjamin Otte
d51b8ff058 window: Port bindings to use shortcuts 2020-03-25 22:36:03 -04:00
Carlos Garnacho
0f73e83f44 gtkwindow: Remove internal popover API
This was only used by text handles, and not anymore.
2020-03-20 15:52:19 +01:00
Matthias Clasen
31db615885 Revert "Merge branch 'disable-window-test' into 'master'"
This reverts commit 3ac4c76b18, reversing
changes made to 6ec96d2e98.
2020-03-19 18:03:16 -04:00
Matthias Clasen
5a6533d8fb window: Name the the controllers 2020-03-18 23:00:51 -04:00
Benjamin Otte
ff6df33b6a accels: Remove GtkAccelGroup 2020-03-18 23:00:51 -04:00
Benjamin Otte
df792a088d application: Replace accelerator handling with shortcuts
API remains the same, but activation is now done via a
shortcutcontroller.

The code uses a controller with global scope so that the
shortcuts are managed with all the other global shortcuts.
2020-03-18 23:00:51 -04:00
Benjamin Otte
4a4bfa0766 shortcut: Change the API for creating shortcuts
When creating shortcuts, there almost always are a trigger and an action
available for use. So make gtk_shortcut_new() take those as arguments.

Also add gtk_shortcut_new_with_arguments() so people can easily pass
those in, too.
2020-03-18 23:00:51 -04:00
Benjamin Otte
e6d0560a82 shortcut: Add GtkShortcutAction
Similar to GtkShortcutTrigger, GtkShortCutAction provides all the
different ways to activate a shortcut.

So far, these different ways are supported:

 - do nothing
 - Call a user-provided callback
 - Call gtk_widget_activate()
 - Call gtk_widget_mnemonic_activate()
 - Emit an action signal
 - Activate an action from the widget's action muxer
 - Activate a GAction
2020-03-18 23:00:51 -04:00
Emmanuele Bassi
a977094e18 window: Remove all old mnemonic handling API 2020-03-18 23:00:51 -04:00
Emmanuele Bassi
09400b6bfe Add GtkShortcutManager
This adds an interface for taking care of shortcut controllers with
managed scope.

Only GtkWindow currently implements this interface, so we need to ensure
that we check if any top-level widget we reach is a shortcuts manager
before we call into it.
2020-03-18 23:00:50 -04:00
Benjamin Otte
bea2dcef8f window: Put F10 accelerator into its own shortcut controller
So instead of relying on gtk_window_activate_key(), it's now using
proper infrastructure.
2020-03-18 23:00:50 -04:00
Benjamin Otte
cc13b47542 window: Get rid of public APIs that shouldn't be
Event controllers should have replaced all of them.
And if they haven't, apps need to fix their code (I'm
looking at you Gimp).
2020-03-18 23:00:50 -04:00
Benjamin Otte
e62154c91f trigger: Add an alternative trigger
And use it.

I just added it to GtkWidget just to show that I can.
The real reason I want it is for gamepad/joystick triggers
in games, so that it becomes possible to select 2 different
triggers (gamepad and keyboard) for the same shortcut.
2020-03-18 23:00:49 -04:00
Benjamin Otte
0f6c5da28d window: Port bindings to use shortcuts 2020-03-18 23:00:49 -04:00
Matthias Clasen
7a46157edf window: Set min size properly
When we are mapping the window, we need to compute
a proper min size, otherwise the 1, 1 sticks and
makes all windows shrinkable to nothing.
2020-03-17 20:46:57 -04:00
Matthias Clasen
c9ec1c6af1 Drop focus-related properties
We don't use these, and they are only implemented on X11.
2020-03-14 19:28:00 -04:00
Matthias Clasen
6f156dad7f window: Drop keep above/below 2020-03-14 15:16:56 -04:00
Matthias Clasen
fb7ef8f62c window: Drop sticky
This is an X11-only concept that we don't have
on Wayland.
2020-03-14 14:34:39 -04:00
Matthias Clasen
dfda88038e window: Drop gtk_window_set_attached_to
We are no longer attaching windows to widgets.
2020-03-14 02:00:10 -04:00
Matthias Clasen
81be6ff46b Move edge-constraints to GdkToplevel 2020-03-12 15:30:11 -04:00
Matthias Clasen
6edff8cd67 gtk: use toplevel state getter 2020-03-12 14:56:20 -04:00
Matthias Clasen
9266881691 window: Use GdkToplevel 2020-03-12 14:56:20 -04:00
Matthias Clasen
11c91065cf window: Drop type hints 2020-03-11 19:36:04 -04:00
Matthias Clasen
b2ae6ce8ff surface: Rename gdk_surface_input_shape_combine_region
There is no shape combining going on anymore, so
call this just gdk_surface_set_input_region, and
remove the offset arguments too. All callers pass
0 anyway.

Update all callers and implementations.
2020-03-11 19:35:56 -04:00
Matthias Clasen
78d71eb439 Simplify surface move/drag api
Drop the with_device variants, and always pass a device.
2020-03-11 19:35:55 -04:00
Matthias Clasen
6f36d9865e Drop gtk_window_begin_move/resize_drag
These are just simple wrappers around GdkSurface
api, and we don't need them.
2020-03-11 19:35:55 -04:00
Benjamin Otte
a411959c91 droptarget: Redo
This is a huge reorganization of GtkDropTarget. I did not know how to
split this up, so it's unfortunately all one commit.

Highlights:

- Split GtkDropTarget into GtkDropTarget and GtkDropTargetAsync
  GtkDropTarget is the simple one that only works with GTypes and offers
  a synchronous interface.
  GtkDropTargetAsync retains the full old functionality and allows
  handling mime types.

- Drop events are handled differently
  Instead of picking a single drop target and sending all DND events to
  it, every event is sent to every drop target. The first one to handle
  the event gets to call gdk_drop_status(), further handlers do not
  interact with the GdkDrop.
  Of course, for the ultimate GDK_DROP_STARTING event, only the first
  one to accept the drop gets to handle it.
  This allows stacking DND event controllers that aren't necessarily
  interested in handling the event or that might decide later to drop
  it.

- Port all widgets to either of those
  Both have a somewhat changed API due to the new event handling.
  For the ones who should use the sync version, lots of cleanup was
  involved to operate on a sync API.
2020-03-02 03:18:55 +01:00
Matthias Clasen
0ffb35c9e7 Drop device grabs
We were not using this api at all, so lets drop it.
2020-02-28 16:27:42 -05:00
Timm Bäder
6056ca9265 window: Carry an extra input region
This will be used in the inspector to make it possible to click through
the inspector window.
2020-02-25 14:18:24 +01:00
Timm Bäder
6b970c6813 widget: Remove set_csd_input_shape
Replace the only caller (unsurprisingly from gtkwindow.c) with a direct
call to gdk_surface_input_shape_combine_region.
2020-02-25 14:18:24 +01:00
Matthias Clasen
a43d13aa74 popover: Drop ::relative-to
It is enough to just set the parent (and make the parent
call gtk_native_check_resize in size_allocate).

This commit removes the relative_to argument to the
constructors of GtkPopover and GtkPopoverMenu, and
updates all callers.
2020-02-24 20:46:41 -05:00
Benjamin Otte
f656cbdc5b Ensure all natives request at least a 1px wide surface
FIXME: Is this necessary?

Could the surfaces just clamp to 1x1 themselves?
We recently declared that surfaces can decide on whatever size they want
so natives need to inspect the size they requested anyway.
2020-02-22 05:50:07 +01:00
Matthias Clasen
e062137b2c motion controller: Match focus event propagation
Make the crossing event generation for pointer events
match what we do for focus now.
2020-02-21 00:51:03 -05:00
Matthias Clasen
5a2f829a40 Split off GtkEventControllerFocus
Split the focus tracking into a separate
GtkEventControllerFocus, and change the API one more time.
We are back to having ::focus-in and ::focus-out signals.

Update all users.
2020-02-21 00:51:03 -05:00
Matthias Clasen
89c3a7ab24 wip: Add more information to crossing events
Add fields for direct descendents to GtkCrossingData,
and populate them when emitting focus change events.

Also add accessors for these fields to GtkEventControllerKey,
and verify that they are set properly in the focus test.

Not done yet: Do the same for pointer crossing events.
2020-02-21 00:51:03 -05:00
Matthias Clasen
b1eaa502df events: reorganize getters
Restructure the getters for event fields to
be more targeted at particular event types.

Update all callers, and replace all direct
event struct access with getters.

As a side-effect, this drops some unused getters.
2020-02-21 00:51:03 -05:00
Matthias Clasen
31bf9da63a Strip const from GdkEvent
Events are refcounted structs, and we generally don't
pass these as const.
2020-02-21 00:51:02 -05:00
Matthias Clasen
2416b4e2a0 Stop using gdk_event_get_target
We can now get the target widget from the gesture
that we are using to find the event in the first
place.
2020-02-21 00:51:02 -05:00
Matthias Clasen
e54e48f6d1 Explicitly pass the target to handle_event
Pass the event propagation target explicitly down to
the event controllers. This is a step towards getting
rid of gdk_event_set_target.
2020-02-21 00:51:02 -05:00
Matthias Clasen
e3158a1bfb Make crossing events handled the same way 2020-02-21 00:50:59 -05:00
Matthias Clasen
23c67f8c67 New focus change handling
Instead of relying on gdk's antiquated crossing events,
create a new GtkCrossingData struct that contains the
actual widgets, and a new event controller vfunc that
expects this struct. This also saves us from making sense
of X's crossing modes and details, and makes for a
generally simpler api.

The ::focus-in and ::focus-out signals of GtkEventControllerKey
have been replaced by a single ::focus-change signal that
takes GtkCrossingData as an argument. All callers have
been updated.
2020-02-21 00:47:53 -05:00
Matthias Clasen
1b2289ad9b Stop using gtk_get_event_target
This is just a thin wrapper around gdk_event_get_target,
so use that directly.
2020-02-21 00:47:53 -05:00
Matthias Clasen
c343031a0e Stop using g_object_ref/unref on events
Use gdk_event_ref/unref instead of g_object_ref/unref.
Events will stop being object soon.
2020-02-21 00:47:53 -05:00
Matthias Clasen
374c9dd880 window: Use event constructors 2020-02-21 00:40:52 -05:00
Benjamin Otte
80ba7fd682 dragdest: Make gtk_drop_target_new() args be transfer full
Saves tons of code.
2020-02-17 04:04:21 +01:00
Benjamin Otte
c1f71ee3e8 window: Remove GtkWindowType and window->type
And remove code that was making decisions on the type and just use
the part for toplevels.
2020-02-14 21:18:49 +01:00
Benjamin Otte
a278edab22 window: Remove type argument from gtk_window_new() 2020-02-14 21:18:49 +01:00
Alexander Larsson
2890cd849f profiler: Add _end_mark() version of _add_mark()
These don't take a duration, instead they call g_get_monotonic_time() to
and subtract the start time for it.

Almost all our calls are like this, and this makes the callsites clearer
and avoids inlining the clock call into the call site.
2020-02-12 11:25:34 +01:00
Alexander Larsson
01d5ad2056 profiler: Make profiler-is-running a macro
When we use if (GDK_PROFILER_IS_RUNNING) this means we get an
inlined if (FALSE) when the compiler support is not compiled in, which
gets rid of all the related code completely.

We also expand to  G_UNLIKELY(gdk_profiler_is_running ()) in the supported
case which might cause somewhat better code generation.
2020-02-12 11:05:01 +01:00
Alexander Larsson
cc643df88b Convert all profiler times from nsec to usec
usec is the scale of the monotonic timer which is where we get almost
all the times from. The only actual source of nsec is the opengl
GPU time (but who knows what the actual resulution of that is).

Changing this to usec allows us to get rid of " * 1000" in a *lot* of
places all over the codebase, which are ugly and confusing.
2020-02-12 10:44:17 +01:00
Alexander Larsson
1698369d52 Merge branch 'icon-theme-api-rework' into 'master'
Icon theme api rework

See merge request GNOME/gtk!1390
2020-02-10 12:45:56 +00:00
Timm Bäder
d3857f8bd3 window: Move variable initialziation just before usage 2020-02-07 13:16:45 -05:00