Merge lp:~evfool/midori/lp792536 into lp:midori

Proposed by Robert Roth
Status: Merged
Approved by: gue5t gue5t
Approved revision: 6558
Merged at revision: 6556
Proposed branch: lp:~evfool/midori/lp792536
Merge into: lp:midori
Diff against target: 73 lines (+49/-0)
1 file modified
midori/midori-browser.c (+49/-0)
To merge this branch: bzr merge lp:~evfool/midori/lp792536
Reviewer Review Type Date Requested Status
gue5t gue5t Approve
Review via email: mp+205852@code.launchpad.net

Commit message

Change tooltips of Reload and ReloadStop actions while shift modifier is pressed

Description of the change

Proposing for merge this simple fix to change the ReloadStop toolbar buttons tooltip in case Shift is pressed, to do a full page reload without caching. The tooltip text is the same as used for the action assigned to Ctrl+Shift+R, so no new string.

To post a comment you must log in.
Revision history for this message
gue5t gue5t (gue5t) wrote :

This looks good. I'll have to double-check that IS_SHIFT doesn't make too many assumptions about e.g. modifier mappings (compared to other code), and after I'll r+ assuming it works right in testing.

Revision history for this message
gue5t gue5t (gue5t) wrote :

This should apply to the Reload action as well as the StopReload one.

Avoid // comments in favor of /**/ ones.

Just checking GDK_KEY_Shift_R and GDK_KEY_Shift_L is not sufficient to determine if the key last pressed placed the keyboard into a "shift" state, due to the complexities of X modifier mapping. For example, by running "xmodmap -e 'add shift = 0x0064'", the letter d key acts like a shift key. I'm not sure how to best do this--one could remember the state from the last keypress, but that leads to the question of whether GTK gets a key release event if the user presses shift, leaves the window, and then releases shift.

Thanks for your work, though! This is a nice bit of polish that helps expose functionality that's even less discoverable right now.

review: Needs Fixing
Revision history for this message
Robert Roth (evfool) wrote :

I have updated the branch with
* setting the tooltip on the Reload action too
* modified the shift handling logic to be fully based on Gdk instead of conditions wizardry. Simply query the current modifier mask on key press/release, and if it contains GDK_SHIFT_MASK, then act accordingly.
* // comments have been removed being unnecessary as this solution is much easier to read
What do you think about this version?

Revision history for this message
gue5t gue5t (gue5t) wrote :

There's one unintended change in behavior with this patch: before the patch, pressing any key with a tooltip open hides the tooltip. After the patch, the tooltip is reshown. This applies to all tooltips, not just the one on the affected actions whose tooltip strings change. It might be a good idea to only set tooltips if the new tooltip is different from what it was previously (i.e. maintain state as mentioned, maybe with g_object_get_data/set_data of a bool on the action, or use the existing state by comparing tooltips before setting).

That's a tiny concern and I'm fine with committing as-is, but I just wanted the change noted nonetheless.

review: Approve
Revision history for this message
Robert Roth (evfool) wrote :

I have updated the code to only set the tooltip if it is different from what it was.
I have also tested the behaviour with tooltip hiding/reappearing on keypress, and in my tests only Shift is causing the tooltip to reappear, other keys (e.g. Ctrl) are only hiding the tooltip.
In the case of reload and reloadstop hiding and reappearing tooltips makes sense, as if we would hide the tooltip on Shift keypress, then there would be no sense in setting the new tooltip :) However I would like to stop the hide/appear on other toolitems, but haven't found a way to do that, only setting different tooltips does not help.

Revision history for this message
gue5t gue5t (gue5t) wrote :

That's all we can do without messing about in GTK internals, I think. Thanks for the tweak!

Revision history for this message
gue5t gue5t (gue5t) :
review: Approve
Revision history for this message
RabbitBot (rabbitbot-a) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Robert Roth (evfool) wrote :

@gue5t gue5t:It seems to me that you've reviewed each revision I have committed, but the RabbitBot doesn't agree, could you please take another quick peek at the branch and Approve again and Merge if you think it's OK?

Revision history for this message
gue5t gue5t (gue5t) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-browser.c'
2--- midori/midori-browser.c 2014-01-06 23:05:10 +0000
3+++ midori/midori-browser.c 2014-02-12 22:56:44 +0000
4@@ -1925,6 +1925,53 @@
5 /* Nothing to do */
6 }
7
8+static void
9+_update_tooltip_if_changed (GtkAction* action,
10+ const gchar* text)
11+{
12+ gchar *old;
13+ g_object_get (action, "tooltip", &old, NULL);
14+ if (g_strcmp0(old, text)) {
15+ g_object_set (action,
16+ "tooltip", text, NULL);
17+ }
18+ g_free (old);
19+}
20+
21+static void
22+_update_reload_tooltip (GtkWidget* widget,
23+ GdkEventKey* event,
24+ gboolean released)
25+{
26+ MidoriBrowser* browser = MIDORI_BROWSER (widget);
27+
28+ /* Update the reload/stop tooltip in case we are holding the hard refresh modifiers*/
29+ GtkAction *reload_stop = _action_by_name (browser, "ReloadStop");
30+ GtkAction *reload = _action_by_name (browser, "Reload");
31+ GdkModifierType mask;
32+ gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, &mask);
33+ const gchar *target;
34+
35+ if ( mask & GDK_SHIFT_MASK)
36+ {
37+ target = _("Reload page without caching");
38+ }
39+ else
40+ {
41+ target = _("Reload the current page");
42+ }
43+ _update_tooltip_if_changed (reload_stop, target);
44+ _update_tooltip_if_changed (reload, target);
45+}
46+
47+static gboolean
48+midori_browser_key_release_event (GtkWidget* widget,
49+ GdkEventKey* event)
50+{
51+ _update_reload_tooltip (widget, event, TRUE);
52+ return FALSE;
53+}
54+
55 static gboolean
56 midori_browser_key_press_event (GtkWidget* widget,
57 GdkEventKey* event)
58@@ -1934,6 +1981,7 @@
59 GtkWidgetClass* widget_class;
60 guint clean_state;
61
62+ _update_reload_tooltip(widget, event, FALSE);
63 /* Interpret Ctrl(+Shift)+Tab as tab switching for compatibility */
64 if (midori_browser_get_nth_tab (browser, 1) != NULL
65 && event->keyval == GDK_KEY_Tab
66@@ -2259,6 +2307,7 @@
67
68 gtkwidget_class = GTK_WIDGET_CLASS (class);
69 gtkwidget_class->key_press_event = midori_browser_key_press_event;
70+ gtkwidget_class->key_release_event = midori_browser_key_release_event;
71
72 gobject_class = G_OBJECT_CLASS (class);
73 gobject_class->dispose = midori_browser_dispose;

Subscribers

People subscribed via source and target branches

to all changes: