From 1094410ff820862eac1088d344aa1657ad7001fb Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 18 Oct 2002 21:22:27 +0000 Subject: [PATCH] add "what happens when you double click the titlebar" setting, patch from 2002-10-18 Havoc Pennington * src/prefs.c, src/frames.c: add "what happens when you double click the titlebar" setting, patch from Sean Middleditch bug #95625. This is basically an "add Windows emulation mode" patch. --- ChangeLog | 6 ++++ src/common.h | 7 +++++ src/core.c | 19 ++++++++++++ src/core.h | 2 ++ src/frames.c | 43 ++++++++++++++++++++------ src/metacity.schemas.in | 17 +++++++++++ src/prefs.c | 67 +++++++++++++++++++++++++++++++++++++++++ src/prefs.h | 2 ++ 8 files changed, 153 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54e1d879b..5056fd0b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-10-18 Havoc Pennington + + * src/prefs.c, src/frames.c: add "what happens when you double + click the titlebar" setting, patch from Sean Middleditch bug + #95625. This is basically an "add Windows emulation mode" patch. + 2002-10-18 Havoc Pennington * src/metacity.schemas.in: move window-click to Super+click not diff --git a/src/common.h b/src/common.h index 0aee2f052..204ccc3b0 100644 --- a/src/common.h +++ b/src/common.h @@ -140,6 +140,13 @@ typedef enum META_FOCUS_MODE_MOUSE } MetaFocusMode; +typedef enum +{ + META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_SHADE, + META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_MAXIMIZE, + META_ACTION_DOUBLE_CLICK_TITLEBAR_LAST +} MetaActionDoubleClickTitlebar; + typedef enum { META_FRAME_TYPE_NORMAL, diff --git a/src/core.c b/src/core.c index 812f63c0c..33bd04ab4 100644 --- a/src/core.c +++ b/src/core.c @@ -322,6 +322,25 @@ meta_core_maximize (Display *xdisplay, meta_window_maximize (window); } +void +meta_core_toggle_maximize (Display *xdisplay, + Window frame_xwindow) +{ + MetaDisplay *display; + MetaWindow *window; + + display = meta_display_for_x_display (xdisplay); + window = meta_display_lookup_x_window (display, frame_xwindow); + + if (window == NULL || window->frame == NULL) + meta_bug ("No such frame window 0x%lx!\n", frame_xwindow); + + if (window->maximized) + meta_window_unmaximize (window); + else + meta_window_maximize (window); +} + void meta_core_unmaximize (Display *xdisplay, Window frame_xwindow) diff --git a/src/core.h b/src/core.h index 7d8dea5f8..3af281841 100644 --- a/src/core.h +++ b/src/core.h @@ -77,6 +77,8 @@ void meta_core_get_size (Display *xdisplay, void meta_core_minimize (Display *xdisplay, Window frame_xwindow); +void meta_core_toggle_maximize (Display *xdisplay, + Window frame_xwindow); void meta_core_unmaximize (Display *xdisplay, Window frame_xwindow); void meta_core_maximize (Display *xdisplay, diff --git a/src/frames.c b/src/frames.c index a6f0c4c2f..f72917005 100644 --- a/src/frames.c +++ b/src/frames.c @@ -1068,18 +1068,41 @@ meta_frames_button_press_event (GtkWidget *widget, { MetaFrameFlags flags; - flags = meta_core_get_frame_flags (gdk_display, frame->xwindow); - - if (flags & META_FRAME_ALLOWS_SHADE) + switch (meta_prefs_get_action_double_click_titlebar ()) { - if (flags & META_FRAME_SHADED) - meta_core_unshade (gdk_display, - frame->xwindow); - else - meta_core_shade (gdk_display, - frame->xwindow); - } + case META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_SHADE: + { + flags = meta_core_get_frame_flags (gdk_display, frame->xwindow); + + if (flags & META_FRAME_ALLOWS_SHADE) + { + if (flags & META_FRAME_SHADED) + meta_core_unshade (gdk_display, + frame->xwindow); + else + meta_core_shade (gdk_display, + frame->xwindow); + } + } + break; + + case META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_MAXIMIZE: + { + MetaFrameFlags flags; + + flags = meta_core_get_frame_flags (gdk_display, frame->xwindow); + + if (flags & META_FRAME_ALLOWS_MAXIMIZE) + { + meta_core_toggle_maximize (gdk_display, frame->xwindow); + } + } + break; + case META_ACTION_DOUBLE_CLICK_TITLEBAR_LAST: + break; + } + return TRUE; } diff --git a/src/metacity.schemas.in b/src/metacity.schemas.in index 7b0d72341..1cf1b5079 100644 --- a/src/metacity.schemas.in +++ b/src/metacity.schemas.in @@ -61,6 +61,23 @@ + + /schemas/apps/metacity/general/action_double_click_titlebar + /apps/metacity/general/action_double_click_titlebar + metacity + string + toggle_shade + + Action on title bar double-click + + This option determines the effects of double-clicking on the + title bar. Current valid options are 'toggle_shade', which will + shade/unshade the window, and 'toggle_maximize' which will + maximize/unmaximize the window. + + + + /schemas/apps/metacity/general/auto_raise /apps/metacity/general/auto_raise diff --git a/src/prefs.c b/src/prefs.c index d44012fc3..efae54cf2 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -32,6 +32,7 @@ */ #define KEY_MOUSE_BUTTON_MODS "/apps/metacity/general/mouse_button_modifier" #define KEY_FOCUS_MODE "/apps/metacity/general/focus_mode" +#define KEY_ACTION_DOUBLE_CLICK_TITLEBAR "/apps/metacity/general/action_double_click_titlebar" #define KEY_AUTO_RAISE "/apps/metacity/general/auto_raise" #define KEY_AUTO_RAISE_DELAY "/apps/metacity/general/auto_raise_delay" #define KEY_THEME "/apps/metacity/general/theme" @@ -56,6 +57,8 @@ static MetaVirtualModifier mouse_button_mods = Mod1Mask; static MetaFocusMode focus_mode = META_FOCUS_MODE_CLICK; static char* current_theme = NULL; static int num_workspaces = 4; +static MetaActionDoubleClickTitlebar action_double_click_titlebar = + META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_SHADE; static gboolean application_based = FALSE; static gboolean disable_workarounds = FALSE; static gboolean auto_raise = FALSE; @@ -87,6 +90,7 @@ static gboolean update_theme (const char *value); static gboolean update_num_workspaces (int value); static gboolean update_application_based (gboolean value); static gboolean update_disable_workarounds (gboolean value); +static gboolean update_action_double_click_titlebar (const char *value); static gboolean update_auto_raise (gboolean value); static gboolean update_auto_raise_delay (int value); static gboolean update_button_layout (const char *value); @@ -268,6 +272,13 @@ meta_prefs_init (void) update_focus_mode (str_val); g_free (str_val); + str_val = gconf_client_get_string (default_client, + KEY_ACTION_DOUBLE_CLICK_TITLEBAR, + &err); + cleanup_error (&err); + update_action_double_click_titlebar (str_val); + g_free (str_val); + bool_val = gconf_client_get_bool (default_client, KEY_AUTO_RAISE, &err); cleanup_error (&err); @@ -533,6 +544,22 @@ change_notify (GConfClient *client, if (update_screen_binding (key, str)) queue_changed (META_PREF_SCREEN_KEYBINDINGS); } + else if (strcmp (key, KEY_ACTION_DOUBLE_CLICK_TITLEBAR) == 0) + { + const char *str; + + if (value && value->type != GCONF_VALUE_STRING) + { + meta_warning (_("GConf key \"%s\" is set to an invalid type\n"), + key); + goto out; + } + + str = value ? gconf_value_get_string (value) : NULL; + + if (update_action_double_click_titlebar (str)) + queue_changed (META_PREF_ACTION_DOUBLE_CLICK_TITLEBAR); + } else if (strcmp (key, KEY_AUTO_RAISE) == 0) { gboolean b; @@ -977,6 +1004,37 @@ meta_prefs_get_disable_workarounds (void) return disable_workarounds; } +static MetaActionDoubleClickTitlebar +action_double_click_titlebar_from_string (const char *str) +{ + if (strcmp (str, "toggle_shade") == 0) + return META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_SHADE; + else if (strcmp (str, "toggle_maximize") == 0) + return META_ACTION_DOUBLE_CLICK_TITLEBAR_TOGGLE_MAXIMIZE; + else + return META_ACTION_DOUBLE_CLICK_TITLEBAR_LAST; +} + +static gboolean +update_action_double_click_titlebar (const char *value) +{ + MetaActionDoubleClickTitlebar old_action = action_double_click_titlebar; + + if (value != NULL) + { + action_double_click_titlebar = action_double_click_titlebar_from_string (value); + + if (action_double_click_titlebar == META_ACTION_DOUBLE_CLICK_TITLEBAR_LAST) + { + action_double_click_titlebar = old_action; + meta_warning (_("GConf key '%s' is set to an invalid value\n"), + KEY_ACTION_DOUBLE_CLICK_TITLEBAR); + } + } + + return (old_action != action_double_click_titlebar); +} + static gboolean update_auto_raise (gboolean value) { @@ -1039,6 +1097,9 @@ meta_preference_to_string (MetaPreference pref) case META_PREF_DISABLE_WORKAROUNDS: return "DISABLE_WORKAROUNDS"; + case META_PREF_ACTION_DOUBLE_CLICK_TITLEBAR: + return "ACTION_DOUBLE_CLICK_TITLEBAR"; + case META_PREF_AUTO_RAISE: return "AUTO_RAISE"; @@ -1417,6 +1478,12 @@ meta_prefs_get_window_bindings (const MetaKeyPref **bindings, *n_bindings = (int) G_N_ELEMENTS (window_bindings) - 1; } +MetaActionDoubleClickTitlebar +meta_prefs_get_action_double_click_titlebar () +{ + return action_double_click_titlebar; +} + gboolean meta_prefs_get_auto_raise () { diff --git a/src/prefs.h b/src/prefs.h index e03b12345..0731a0209 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -30,6 +30,7 @@ typedef enum { META_PREF_MOUSE_BUTTON_MODS, META_PREF_FOCUS_MODE, + META_PREF_ACTION_DOUBLE_CLICK_TITLEBAR, META_PREF_AUTO_RAISE, META_PREF_AUTO_RAISE_DELAY, META_PREF_THEME, @@ -70,6 +71,7 @@ const char* meta_prefs_get_command (int i); char* meta_prefs_get_gconf_key_for_command (int i); void meta_prefs_get_button_layout (MetaButtonLayout *button_layout); +MetaActionDoubleClickTitlebar meta_prefs_get_action_double_click_titlebar (void); void meta_prefs_set_num_workspaces (int n_workspaces);