[gnome-calendar/ui-rewrite] window: handle key pressed properly
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/ui-rewrite] window: handle key pressed properly
- Date: Mon, 10 Nov 2014 13:58:12 +0000 (UTC)
commit 801bfa525dd79d71ae0e17c4f45ce5b1cac89d76
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Nov 4 10:41:06 2014 -0500
window: handle key pressed properly
Before the code handling key presses was an unreadable mess. Now we use
gtk_accelerator_get_default_mod_mask as stated on Gtk documentation.
src/gcal-window.c | 46 +++++++++++++++++++++++++++-------------------
1 files changed, 27 insertions(+), 19 deletions(-)
---
diff --git a/src/gcal-window.c b/src/gcal-window.c
index dcaf5c9..e50323b 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -204,38 +204,46 @@ key_pressed (GtkWidget *widget,
gpointer user_data)
{
GcalWindowPrivate *priv;
+ GdkModifierType modifiers;
priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
+ modifiers = gtk_accelerator_get_default_mod_mask ();
g_debug ("Catching key events");
+ /* case 1:close leave new event mode */
if (priv->new_event_mode &&
event->keyval == GDK_KEY_Escape)
{
set_new_event_mode (GCAL_WINDOW (user_data), FALSE);
return TRUE;
}
- else
+
+ /* case 2: write in new-event-widget entry */
+ if (priv->new_event_mode)
+ return FALSE;
+
+ /* case 3: leave search-mode*/
+ if (priv->search_mode && event->keyval == GDK_KEY_Escape)
{
- if (priv->new_event_mode)
- return FALSE;
-
- if ((event->state & GDK_META_MASK) != 0 ||
- (event->state & GDK_CONTROL_MASK) != 0 ||
- event->keyval == GDK_KEY_Control_L ||
- event->keyval == GDK_KEY_Control_R ||
- event->keyval == GDK_KEY_Meta_L ||
- event->keyval == GDK_KEY_Meta_R ||
- event->keyval == GDK_KEY_Alt_L ||
- event->keyval == GDK_KEY_Alt_R)
- {
- return FALSE;
- }
+ gcal_window_set_search_mode (GCAL_WINDOW (widget), FALSE);
+ return TRUE;
+ }
- if (priv->search_mode && event->keyval == GDK_KEY_Escape)
- gcal_window_set_search_mode (GCAL_WINDOW (widget), FALSE);
- if (!priv->search_mode)
- gcal_window_set_search_mode (GCAL_WINDOW (widget), TRUE);
+ /* case 4: write into search-mode entry */
+ if (priv->search_mode)
+ return FALSE;
+
+ /* case 5: open search-mode */
+ if (!priv->search_mode &&
+ gdk_keyval_to_unicode (event->keyval) != 0 &&
+ ((event->state & modifiers & GDK_META_MASK) == 0) &&
+ ((event->state & modifiers & GDK_SUPER_MASK) == 0) &&
+ ((event->state & modifiers & GDK_HYPER_MASK) == 0) &&
+ ((event->state & modifiers & GDK_CONTROL_MASK) == 0))
+ {
+ gcal_window_set_search_mode (GCAL_WINDOW (widget), TRUE);
+ return FALSE;
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]