After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 610515 - No way to programmatically update visual state of a button
No way to programmatically update visual state of a button
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkButton
2.99.x
Other All
: Normal critical
: 3.0
Assigned To: gtk-bugs
gtk-bugs
[gnome3-important]
Depends on:
Blocks: 580557 600475 628364 632729 634541
 
 
Reported: 2010-02-20 08:48 UTC by Xan Lopez
Modified: 2018-04-15 00:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implement gtk_button_depress (4.73 KB, patch)
2010-04-13 13:25 UTC, Christian Dywan
none Details | Review
Implement gtk_button_depress + _release (6.42 KB, patch)
2010-04-13 13:35 UTC, Christian Dywan
none Details | Review

Description Xan Lopez 2010-02-20 08:48:06 UTC
GtkButtons only react to the left button by default. That is, the button_press/release handlers check that this was the mouse button used, and will only call gtk_button_pressed/released in that case, which eventually will also trigger 'clicked'.

Epiphany has a policy in its toolbar buttons that, for any action, if the action could conceivably be done either in the current window or in a new tab (eg, go back), left click will do it in the current window and middle click will do it in a new tab. For this it needs buttons to react to a middle click, so it connects to button-{press,release}-event on them and calls the deprecated functions if event->button == 2, since it knows GtkButton won't do it.

Since those functions are deprecated now, it seems there's no sane way of doing this anymore. Am I wrong? Should GtkButton we modified to accept middle clicks by default or through an option?
Comment 1 Matthias Clasen 2010-02-23 15:56:40 UTC
I would say those deprecations were simply in error then, and should be undone.
Comment 2 Matthias Clasen 2010-02-23 16:03:36 UTC
Alternatively, use g_signal_emit_by_name
Comment 3 Xan Lopez 2010-02-23 16:12:24 UTC
(In reply to comment #2)
> Alternatively, use g_signal_emit_by_name

The signals are also deprecated.
Comment 4 Christian Dywan 2010-02-25 08:02:04 UTC
What GtkButton::pressed does is, connect to GtkWidget::button-press-event and check the event type and button. released is implemented analogously with button-release-event.

Why don't you use the widget signals now?
Comment 5 Xan Lopez 2010-02-25 08:39:13 UTC
(In reply to comment #4)
> What GtkButton::pressed does is, connect to GtkWidget::button-press-event and
> check the event type and button. released is implemented analogously with
> button-release-event.
> 
> Why don't you use the widget signals now?

Use them how? What I basically need is the default handlers for GtkButton::pressed and GtkButton::released to run, since they are the ones that update the internal state of the widget correctly. I can't neither call the functions nor emit the signals, since they are theoretically deprecated. I am *already* connecting to button-press-event and button-release-event, since as I said in my first comment it's there where I call the deprecated functions. If I emit the signals again I would enter an infinite loop.

Might be missing what you are suggesting, but I don't see how this can be solved using the public non-deprecated APIs.
Comment 6 Christian Dywan 2010-02-25 09:01:38 UTC
Ah, so the actual problem is that there is no API to make buttons look pressed down. And until now you used the signals as a hack to achieve that.

One possibility would be to revive the functions and document them to update the visual state of a button programmatically.
Comment 7 Xan Lopez 2010-02-25 09:05:52 UTC
(In reply to comment #6)
> Ah, so the actual problem is that there is no API to make buttons look pressed
> down. And until now you used the signals as a hack to achieve that.
> 
> One possibility would be to revive the functions and document them to update
> the visual state of a button programmatically.

Well, the default handlers also update various internal state flags and emit the 'clicked' signal (which I need), so it's not only about appearance. The problem is that there's no way to programatically press a button (both the action and the looks of it) and the button by itself won't react to anything other than left click.
Comment 8 Javier Jardón (IRC: jjardon) 2010-04-09 13:10:32 UTC
Seems that nautilus is affected by this too.

Take a look to bug #600475
This is patch attached there: https://bugzilla.gnome.org/attachment.cgi?id=148472&action=edit
Comment 9 Christian Dywan 2010-04-13 13:25:10 UTC
Created attachment 158603 [details] [review]
Implement gtk_button_depress

This implements gtk_button_depress, which basically sets the internal state of the button so that it is drawn and treated as depressed.  I also changed the release handler so that any mouse button can release the button, but only the first button triggers the 'clicked' and 'released' signals.
The main difference with the old API is that it doesn't depend on the signals, so we can remove them in the future.

I left a test snippet in there, in testgtk, which shows how it works.
Comment 10 Christian Dywan 2010-04-13 13:35:02 UTC
Created attachment 158604 [details] [review]
Implement gtk_button_depress + _release

For completeness, the addition of gtk_button_release, if we want to allow releasing programatically. Albeit I'm not sure how useful that is in practise. It is not needed for the cases where Ephy or Nautilus just need other mouse buttons.
Comment 11 Michael Natterer 2010-04-13 13:44:55 UTC
I don't get this. The original request was to simply be able to change
event->button = 2 to event->button = 1 in the button_press_event handler,
right?

So where is the problem in simply subblassing GtkButton, implementing
GtkWidget::button_press_event() and ::button_release_event(), create
a new GdkEventButton with event->button = 1 and chaining up?
Comment 12 Xan Lopez 2010-06-11 19:26:33 UTC
(In reply to comment #11)
> I don't get this. The original request was to simply be able to change
> event->button = 2 to event->button = 1 in the button_press_event handler,
> right?
> 
> So where is the problem in simply subblassing GtkButton, implementing
> GtkWidget::button_press_event() and ::button_release_event(), create
> a new GdkEventButton with event->button = 1 and chaining up?

Other than being a horribly laborious task for such a simple need, nothing I guess. If being able to press buttons with other than button=1 is deemed reasonable I'd rather see the API undeprecated or GtkButton fixed to cope with it.
Comment 13 Diego Escalante Urrelo (not reading bugmail) 2010-12-15 15:07:07 UTC
Any new opinion on this? GTK+ is going to freeze API soon, so perhaps we want to decide something :P.
(raising importance since Nautilus and Epiphany need this)
Comment 14 Carlos Garnacho 2011-01-27 14:53:36 UTC
How about setting GTK_STATE_FLAG_ACTIVE on button_press_event() if event->button==2?
Comment 15 Diego Escalante Urrelo (not reading bugmail) 2011-01-31 02:54:27 UTC
A quick test throws:
 - the button is drawn as clicked/released, but it is not "clicked" (no signal is emitted, so the button does nothing)
 - set_state_flag + unset_state_flag produce some funky results

The second point is trivial of course.
Comment 16 Carlos Garnacho 2011-02-03 10:49:24 UTC
Well, in a subclass you can perfectly make it emit a signal :), this bug is about programmatically updating the visual state of the button, and that's doable AFAICS
Comment 17 Xan Lopez 2011-02-03 11:52:12 UTC
(In reply to comment #16)
> Well, in a subclass you can perfectly make it emit a signal :), this bug is
> about programmatically updating the visual state of the button, and that's
> doable AFAICS

I'm not sure why the title was updated to say that, but my comments make it quite clear that the deprecated functions update both the appearance and the internal state of the widget, including making it actually emit "clicked".

If the solution is to subclass buttons I guess we can go with that, but honestly I'm not sure of why GtkButton shouldn't be just updated to react to middle and right clicks?
Comment 18 Dhaivat Pandya 2011-02-16 20:59:10 UTC
What's the current situation for this bug? Bypass it, or fix it with a patch, because this needs to be in before GNOME 3, I suppose.
Comment 19 André Klapper 2011-03-03 21:16:36 UTC
[Removing GNOME3.0 target as decided in release-team meeting on March 03, 2011.
This report has an "important" categorisation for GNOME3.0 but is not considered a hard blocker. For querying use the corresponding whiteboard entry added.]
Comment 20 Timothy Arceri 2013-10-14 06:45:54 UTC
Did this make it into GTK+3? Is this bug still relevant?
Comment 21 Matthias Clasen 2018-02-10 05:16:44 UTC
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
Comment 22 Matthias Clasen 2018-04-15 00:09:38 UTC
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla.

If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab:

https://gitlab.gnome.org/GNOME/gtk/issues/new