Commit Graph

49 Commits

Author SHA1 Message Date
Matthias Clasen
3cccb00f51 actionmuxer: Drop SECTION
This is private.
2021-03-11 16:37:37 +00:00
Benjamin Otte
96e1b85c2c gdkarray: Add a "stolen" boolean to splice()
If set to TRUE, does not call the free func for the removed items.

This can be used to move items between arrays without having to do the
refcounting dance.
2020-12-24 06:38:45 +01:00
Christian Hergert
b68e0bb3fb muxer: add helper to get group by name
This is useful when you need to read a group back out of the muxer.
2020-12-02 19:44:02 -08:00
Matthias Clasen
4bd2595421 actionmuxer: Make it possible to enumerate local actions
This will be useful for exposing actions via the
AT-SPI Actions interface.

Update all callers.
2020-10-15 16:32:55 -04:00
Benjamin Otte
d375dce9f5 Replace "gchar" with "char" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d7266b25ba Replace "gint" with "int" 2020-07-25 00:47:36 +02:00
Matthias Clasen
486fbce42b actionmuxer: Update docs and clean up headers
Update the doc comment at the top to describe the
current  functionality of GtkActionMuxer.
2020-07-20 08:24:54 -04:00
Matthias Clasen
ed92026632 actionmuxer: Use an array for accels
We have a lot of accels across all the muxers, but the vast
majority has just one or two, so an array is going to be
smaller and faster for this.
2020-07-20 08:24:54 -04:00
Matthias Clasen
05e614feb7 actionmuxer: Create observed_actions and groups on demand
The vast majority of action muxers don't have observers or
groups, so we can avoid the overhead of carrying all these
empty hash tables.
2020-07-20 08:24:54 -04:00
Matthias Clasen
9b294eb94e Add gtk_action_muxer_list_actions
This is needed to reinstate the actions support
in the inspector.
2020-07-20 08:24:53 -04:00
Matthias Clasen
96d42cf1cc actionmuxer: Stop implementing GActionGroup
Instead of implementing the GActionGroup interface
and using its signals for propagating changes up
and down the muxer hierarchy, use the GtkActionObserver
mechanism. This cuts down on the signal emission
overhead.
2020-07-20 08:24:53 -04:00
Matthias Clasen
14bb12125f actionmuxer: Add some more api
We want to drop the GActionGroup interface from
GtkActionMuxer, so add the necessary api directly
to GtkActionMuxer itself.
2020-07-20 08:24:14 -04:00
Matthias Clasen
ab67a81f11 Speed up action muxer setup more
Don't emit signals for group insertion/removal
if nobody is listening.
2020-07-20 08:24:14 -04:00
Matthias Clasen
aa76f7e210 Speed up action muxer setup
We don't need to duplicate all these action names and
emit all these signals if nobody is listening.
2020-07-20 08:24:14 -04:00
Yuri Chornoivan
c0cf839729 Fix minor typos 2020-06-18 10:47:16 +03:00
Matthias Clasen
c4a47e218f Speed up class action hookup
No need to construct a detailed signal name for
every action when we can just look up the signal ID
once and use the quark that the GParamSpec already
has. Also, we don't need to loop over the actions
every time we get a notification.
2020-04-28 20:22:26 -04:00
Matthias Clasen
b968ced567 Reshuffle action muxer initialization
We were having a problem where property actions were
not getting state updates because prop_actions_connect
was triggered from some instance_init function while
the widget class is not in place yet.

Delay that call until the widget is fully constructed,
so we can guarantee that we are dealing with the
correct class private struct, and see all class actions.
2020-04-28 18:37:43 -04:00
Christian Hergert
b5b836668a muxer: force muxer dispoal as part of widget dispose
We need to cleanup state here immediately so that we do not potentially
access the g_class private data after it been finalized. This ensures that
the borrowed reference is dropped by the muxer.
2020-03-25 14:02:59 -07:00
Christian Hergert
ccac404f28 widget: fix class private data usage to be _init() safe
Before this commit, adding GtkWidgetAction to class private data would
require copying the actions to each subclass as they were built or
modified. This was convenient in that it is a sort of "copy on write"
semantic.

However, due to the way that GTypeInstance works with base _init()
functions, the "g_class" pointer in GTypeInstance is updated as each
_init() function is called. That means you cannot access the subclasses
class private data, but only the parent class private data.

If instead we use a singly linked list of GtkWidgetAction, each subclass
has their own "head" yet all subclasses share the tail of the
GtkWidgetAction chain.

This creates one bit of complexity though. You need a stable way to know
which "bit" is the "enabled" bit of the action so we can track enabled
GAction state. That is easily solved by calculating the distance to the
end of the chain for a given action so that base classes sort ahead of
subclasses. Since the parent class always knows its parent's actions, the
position is stable.

A new dynamic bitarray helper also helps us avoid allocations in all the
current cases (up to 64 actions per widget) and dynamically switches to
malloc if that is to ever be exceeded.
2020-03-20 11:17:56 -07:00
Timm Bäder
4123c85021 actionmuxer: Plug a memory leak 2019-07-07 07:24:00 +02:00
Matthias Clasen
3b6ee32f83 Fix a crash in action muxer destruction
I've seen a crash when the action muxer gets
disposed during widget destroy, and tries to
disconnect from widget signals too late.

There is no real need to disconnect, since the
only time an action muxer is going away is when
its widget is destroyed, so just don't do it.
2019-06-30 18:37:32 +00:00
Matthias Clasen
8fd968e5bf action muxer: Don't activate disabled actions
We really shouldn't.
2019-06-23 01:39:26 +00:00
Matthias Clasen
ad4a81e9df action muxer: Change inheritance
Previously, we would not look any further for
an action once we found a match for the prefix,
defining inheritance by groups. Change this to
inheritance for individual actions, since we
are moving towards individual actions as the
main ingredient in GTKs action support.
2019-06-22 22:51:23 +00:00
Matthias Clasen
95e5472ade action muxer: Remove unused api 2019-06-22 22:38:14 +00:00
Matthias Clasen
d1f4068b94 Replace stateful actions by property actions
The only cases of stateful actions we've seen
so far have been boolean properties, and we
don't really want to add much state handling
API, so lets just go with property actions
for now.

Adapt the only user in GtkText.
2019-06-22 17:03:38 -04:00
Matthias Clasen
152eabbaba widget actions: Add an explicit state type
Make the state type part of the API for installing
stateful widget actions. That lets us introspect it.

Update all callers.
2019-06-21 22:47:40 -04:00
Matthias Clasen
ef031e1a9d Allow registering actions per-class
Add a facility to register and install actions
at class init time. The intended use for these
actions is for

a) context and other model-based menus
b) key bindings

Most of these actions are going to be stateless,
so add separate apis for the simple and stateful
cases.

We avoid creating an action group for these by
teaching the action muxer about these actions.
The action muxer also maintains the enabled
state for these actions.
2019-06-18 14:47:33 -04:00
Matthias Clasen
9b62da10e6 Give the action muxer a widget
This will be used in the future to obtain
widget class actions.
2019-06-18 06:12:50 -04:00
Matthias Clasen
9bb2d1eb5c widget: Remove gtk_widget_list_action_prefixes
This function was added just for the inspector,
and is not used there anymore. Drop it.
2019-06-15 21:40:38 -04:00
Matthias Clasen
3b565d7f6e action muxer: cosmetics 2019-06-15 21:40:17 -04:00
Matthias Clasen
db7f0189dd action muxer: Add some convenience api
Instead of duplicating this code in multiple places,
add an api to look up an action group for a prefixed
name, and return the unprefixed name at the same time.
2019-06-15 21:40:12 -04:00
Matthias Clasen
f1b9e7c23b Rename a bunch of private headers
We want to follow the convention that all
private headers have names ending in private.h
2019-06-10 03:10:13 +00:00
Christian Hergert
41e373f10c gtk: fix all uses of g_cclosure_marshal_generic
This adds specific marshallers for all of the locations where a generic
marshaller is being used. It also provides va_marshallers to reduce the
chances that we get stack traces from perf going through ffi_call_unix64.

This is forward ported from gtk-3-24.

# Conflicts:
#	gtk/gtkeventcontrollerkey.c
#	gtk/gtkeventcontrollermotion.c
#	gtk/gtkgesture.c
#	gtk/gtkgesturemultipress.c
2019-06-02 14:24:51 -07:00
Emmanuele Bassi
fcaa9aa22d Rename GtkActionMuxer's private header
Follow the naming policy for private headers.
2018-02-02 10:28:17 +01:00
Sébastien Wilmet
3b988ce523 app: share function to normalise detailed action name
Put the function in gtkactionmuxer.c, where
gtk_print_action_and_target() is implemented.

https://bugzilla.gnome.org/show_bug.cgi?id=764879
2016-04-22 12:40:08 +02:00
Ting-Wei Lan
0f120ea510 Cast the return value of g_array_free to void* before casting to char**
Let the compiler know that we don't want to use it as char*, so there is
no alignment error.

https://bugzilla.gnome.org/show_bug.cgi?id=760350
https://bugzilla.gnome.org/show_bug.cgi?id=755659
2016-01-11 00:23:46 +08:00
Matthias Clasen
66f0bdee0a Intern all signal names beforehand
This avoids pointless allocations
2015-09-12 12:50:39 -04:00
Christian Hergert
661da5558c widget: add helpers to resolve GActionGroups available to GtkWidget
These functions, while added for use by the GTK inspector, are generally
useful to applications that need to resolve what action groups are
available to a particular GtkWidget.

https://bugzilla.gnome.org/show_bug.cgi?id=741386
2014-12-11 15:25:41 -08:00
Matthias Clasen
0b88b869e6 GtkActionMuxer: Plug a memory leak
valgrind complained that we leak the primary_accels table.
2014-06-28 22:37:14 -04:00
Matthias Clasen
4396bbdb3c GtkActionMuxer: Add getters
Add a way to enumerate all prefixes, and to get the
action group for a prefix.

https://bugzilla.gnome.org/show_bug.cgi?id=730095
2014-05-14 21:27:56 -04:00
William Jon McCann
13998c55e7 docs: use proper quotations instead of '*' 2014-02-07 14:22:39 -05:00
William Jon McCann
2a45418b67 docs: use proper quotes 2014-02-05 15:08:42 -05:00
William Jon McCann
56f76214b7 docs: don't use <varnam> 2014-02-04 18:32:42 -05:00
William Jon McCann
a22358c0c0 docs: use ` instead of <literal> 2014-02-04 18:24:29 -05:00
William Jon McCann
e24d1626a5 docs: mark gtkdoc blocks as private for internal only API 2014-01-21 23:20:38 -05:00
Daniel Svensson
4d41903548 Use g_return_val_if_fail where return value needed.
https://bugzilla.gnome.org/show_bug.cgi?id=710987
2013-10-29 17:12:23 -04:00
Ryan Lortie
3f8c235593 GtkActionMuxer: store primary accels
Reuse the existing infrastructure in GtkActionMuxer for propagation of
accelerator information: in particular, what accel label ought to appear
on menu items for a particular action and target.

This is a good idea because we want accels to travel along with the
actions that they're tied to and reusing GtkActionMuxer will allow us to
do that without creating another hierarchy of a different class for the
sole purpose of filling in accel labels on menu items.

Doing it this ways also allows those who copy/paste GtkActionMuxer to
insert the accels for themselves.

Add a new method on the GtkActionObserver interface to report changes.

This patch introduces a new concept: "action and target" notation for
actions.  This format looks like so:

  "'target'|app.action"

or for non-targeted actions:

  "|app.action"

and it is used over a number of possible alternative formats for some
good reasons:

 - it's very easy to get a nul-terminated action name out of this format
   when we need it, by using strrchr('|') + 1

 - we can also get the target out of it using g_variant_parse() because
   this function takes a pointer to a 'limit' character that is not
   parsed past: we use the '|' for this

 - it's extremely easy to hash on this format (just use a normal string
   hash) vs. attempting to hash on a string plus a GVariant

A close contender was to use detailed action strings here, but these are
not used for two reasons:

 - it's not possible to easily get the action name or target out of the
   strings without more work than the "action and target" format
   requires

 - we still intend to use detailed action strings on API (since they are
   a lot nicer to look at) but detailed action strings can be given in
   non-canonical forms (eg: 'foo::bar' and 'foo("bar")' are equivalent)
   so we'd have to go through a normalisation step anyway.  Since we're
   doing that already, we may as well convert to a more convenient
   internal format.

This new "action and target" format is going to start appearing in a lot
more places as action descriptions are introduced.

I suspect that nobody is using '|' in their action names, but in case I
am proven wrong, we can always switch to using something more exotic as
a separator character (such as '\x01' or '\xff' or the like).
2013-10-15 09:24:11 -04:00
Jasper St. Pierre
6030ba4803 action stuff: Introspection fixes 2013-05-13 16:33:42 -04:00
Ryan Lortie
6c49cd0ea6 action stuff: stop abusing GLib's namespace
Rename our internal GActionMuxer, GActionObserver and GActionObservable
classes and interfaces to have names in our own namespace.

These classes were originally intended for GIO but turned out to be too
special-purpose to be useful there, so we never made them public API but
have just been copying them around (without bothering to properly rename
them).  Now that other people will be copying them out of Gtk, it's even
more important to prevent this namespace abuse from spreading further.
2013-05-13 16:33:42 -04:00