Revise and unitfy behavior modulating modifier handling

We define modfifier macros that indicate whether a modifier
indicates a new window, new tab, background tab or scrolling.

Modifier checks in the address entry, the search entry and view
now use the same consistent modifiers.
This commit is contained in:
Christian Dywan 2010-01-22 23:11:00 +01:00
parent dc25035e29
commit 82cb12b605
4 changed files with 39 additions and 40 deletions

View file

@ -327,7 +327,7 @@ midori_location_action_treeview_button_press_cb (GtkWidget* treeview,
gtk_tree_model_get (action->completion_model, &iter, URI_COL, &uri, -1);
gtk_entry_set_text (GTK_ENTRY (action->entry), uri);
g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
(event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
MIDORI_MOD_NEW_TAB (event->state));
g_free (uri);
return TRUE;
@ -932,7 +932,7 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
if (is_enter)
g_signal_emit (action, signals[SUBMIT_URI], 0, uri,
(event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
MIDORI_MOD_NEW_TAB (event->state));
g_free (uri);
return TRUE;
@ -942,7 +942,7 @@ midori_location_action_key_press_event_cb (GtkEntry* entry,
if (is_enter)
if ((text = gtk_entry_get_text (entry)) && *text)
g_signal_emit (action, signals[SUBMIT_URI], 0, text,
(event->state & GDK_CONTROL_MASK) ? TRUE : FALSE);
MIDORI_MOD_NEW_TAB (event->state));
break;
case GDK_Escape:
{

View file

@ -357,15 +357,15 @@ midori_search_action_key_press_event_cb (GtkWidget* entry,
case GDK_Return:
text = gtk_entry_get_text (GTK_ENTRY (entry));
g_signal_emit (search_action, signals[SUBMIT], 0, text,
(event->state & GDK_MOD1_MASK) ? TRUE : FALSE);
MIDORI_MOD_NEW_TAB (event->state));
search_action->last_proxy = entry;
return TRUE;
case GDK_Up:
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_SCROLL (event->state))
_midori_search_action_move_index (search_action, - 1);
return TRUE;
case GDK_Down:
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_SCROLL (event->state))
_midori_search_action_move_index (search_action, + 1);
return TRUE;
}

View file

@ -1237,47 +1237,33 @@ gtk_widget_button_press_event_cb (WebKitWebView* web_view,
case 1:
if (!link_uri)
return FALSE;
#if HAVE_OSX
/* FIXME: Test for Command key */
if (0)
#else
if (event->state & GDK_CONTROL_MASK)
#endif
if (MIDORI_MOD_NEW_TAB (event->state))
{
/* Open link in new tab */
background = view->open_tabs_in_the_background;
if (event->state & GDK_SHIFT_MASK)
if (MIDORI_MOD_BACKGROUND (event->state))
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
return TRUE;
}
else if (event->state & GDK_SHIFT_MASK)
else if (MIDORI_MOD_NEW_WINDOW (event->state))
{
/* Open link in new window */
g_signal_emit (view, signals[NEW_WINDOW], 0, link_uri);
return TRUE;
}
else if (event->state & GDK_MOD1_MASK)
{
/* Open link in new tab */
background = view->open_tabs_in_the_background;
if (event->state & GDK_CONTROL_MASK)
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
return TRUE;
}
break;
case 2:
if (link_uri)
{
/* Open link in new tab */
background = view->open_tabs_in_the_background;
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_BACKGROUND (event->state))
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, link_uri, background);
return TRUE;
}
else if (event->state & GDK_CONTROL_MASK)
else if (MIDORI_MOD_SCROLL (event->state))
{
midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0);
return FALSE; /* Allow Ctrl + Middle click */
@ -1304,36 +1290,43 @@ gtk_widget_button_press_event_cb (WebKitWebView* web_view,
GDK_SELECTION_PRIMARY);
if ((uri = gtk_clipboard_wait_for_text (clipboard)))
{
KatzeArray* empty_array = katze_array_new (KATZE_TYPE_ITEM);
guint i = 0;
while (uri[i++] != '\0')
if (uri[i] == '\n' || uri[i] == '\r')
uri[i] = ' ';
new_uri = sokoke_magic_uri (g_strstrip (uri), empty_array, NULL);
g_object_unref (empty_array);
if (!new_uri)
g_strstrip (uri);
/* Hold Alt to search for the selected word */
if (event->state & GDK_MOD1_MASK)
{
gchar* search;
g_object_get (view->settings, "location-entry-search",
&search, NULL);
new_uri = sokoke_search_uri (search, uri);
KatzeArray* empty_array = katze_array_new (KATZE_TYPE_ITEM);
new_uri = sokoke_magic_uri (uri, empty_array, NULL);
g_object_unref (empty_array);
if (!new_uri)
{
gchar* search;
g_object_get (view->settings, "location-entry-search",
&search, NULL);
new_uri = sokoke_search_uri (search, uri);
}
katze_assign (uri, new_uri);
}
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_NEW_TAB (event->state))
{
background = view->open_tabs_in_the_background;
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_BACKGROUND (event->state))
background = !background;
g_signal_emit (view, signals[NEW_TAB], 0, new_uri, background);
g_signal_emit (view, signals[NEW_TAB], 0, uri, background);
}
else
{
midori_view_set_uri (MIDORI_VIEW (view), new_uri);
midori_view_set_uri (MIDORI_VIEW (view), uri);
gtk_widget_grab_focus (GTK_WIDGET (view));
}
g_free (new_uri);
return TRUE;
}
g_free (uri);
}
}
break;
#if WEBKIT_CHECK_VERSION (1, 1, 15)
@ -1409,7 +1402,7 @@ gtk_widget_scroll_event_cb (WebKitWebView* web_view,
{
event->state = event->state & MIDORI_KEYS_MODIFIER_MASK;
if (event->state & GDK_CONTROL_MASK)
if (MIDORI_MOD_SCROLL (event->state))
{
if (event->direction == GDK_SCROLL_DOWN)
midori_view_set_zoom_level (view,

View file

@ -13,6 +13,12 @@
#ifndef __SOKOKE_H__
#define __SOKOKE_H__ 1
/* Common behavior modifiers */
#define MIDORI_MOD_NEW_WINDOW(state) (state & GDK_SHIFT_MASK)
#define MIDORI_MOD_NEW_TAB(state) (state & GDK_CONTROL_MASK)
#define MIDORI_MOD_BACKGROUND(state) (state & GDK_SHIFT_MASK)
#define MIDORI_MOD_SCROLL(state) (state & GDK_CONTROL_MASK)
#include <katze/katze.h>
#include <webkit/webkit.h>