From 65b829a015b13ef3fe21650beda53523904047aa Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 1 Jun 2007 01:51:17 +0000 Subject: [PATCH] rename behavior tab to windows. add mouse tab with some super cool code! --- Makefile.am | 6 +- src/main.c | 6 +- src/mouse.c | 195 ++++++++++++++++++++++++++++++++++ src/mouse.h | 24 +++++ src/obconf.glade | 133 +++++++++++++++++++++-- src/strings.c | 6 +- src/{behavior.c => windows.c} | 48 ++------- src/{behavior.h => windows.h} | 8 +- 8 files changed, 364 insertions(+), 62 deletions(-) create mode 100644 src/mouse.c create mode 100644 src/mouse.h rename src/{behavior.c => windows.c} (78%) rename src/{behavior.h => windows.h} (83%) diff --git a/Makefile.am b/Makefile.am index f66313d..8cce7b9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,8 +41,10 @@ src_obconf_SOURCES = \ src/about.c \ src/archive.c \ src/archive.h \ - src/behavior.c \ - src/behavior.h \ + src/windows.c \ + src/windows.h \ + src/mouse.c \ + src/mouse.h \ src/desktops.c \ src/desktops.h \ src/dock.h \ diff --git a/src/main.c b/src/main.c index c8008a2..27144d7 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,8 @@ #include "archive.h" #include "theme.h" #include "appearance.h" -#include "behavior.h" +#include "windows.h" +#include "mouse.h" #include "desktops.h" #include "dock.h" #include "preview_update.h" @@ -156,7 +157,8 @@ int main(int argc, char **argv) theme_setup_tab(); appearance_setup_tab(); - behavior_setup_tab(); + windows_setup_tab(); + mouse_setup_tab(); desktops_setup_tab(); dock_setup_tab(); diff --git a/src/mouse.c b/src/mouse.c new file mode 100644 index 0000000..327680d --- /dev/null +++ b/src/mouse.c @@ -0,0 +1,195 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + mouse.c for ObConf, the configuration tool for Openbox + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "main.h" +#include "tree.h" +#include "gettext.h" +#include + +static gboolean mapping = FALSE; +static xmlNodePtr saved_custom = NULL; + +#define TITLEBAR_MAXIMIZE 0 +#define TITLEBAR_SHADE 1 +#define TITLEBAR_CUSTOM 2 + +static gint read_doubleclick_action(); +static void write_doubleclick_action(gint a); +static void on_titlebar_doubleclick_custom_activate(GtkMenuItem *w, + gpointer data); + +void mouse_setup_tab() +{ + GtkWidget *w, *w1, *w2; + GtkSizeGroup *group; + gint a; + + mapping = TRUE; + + w1 = get_widget("doubleclick_time"); + w2 = get_widget("drag_threshold"); + group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + gtk_size_group_add_widget(group, w1); + gtk_size_group_add_widget(group, w2); + + w1 = get_widget("doubleclick_time_label"); + w2 = get_widget("drag_threshold_label"); + group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + gtk_size_group_add_widget(group, w1); + gtk_size_group_add_widget(group, w2); + + w = get_widget("doubleclick_time"); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), + tree_get_int("mouse/doubleClickTime", 200)); + + w = get_widget("drag_threshold"); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), + tree_get_int("mouse/dragThreshold", 3)); + + w = get_widget("titlebar_doubleclick"); + a = read_doubleclick_action(); + if (a == TITLEBAR_CUSTOM) { + GtkWidget *i = gtk_menu_item_new_with_label(_("Custom actions")); + g_signal_connect(i, "activate", + G_CALLBACK (on_titlebar_doubleclick_custom_activate), + NULL); + gtk_menu_shell_append + (GTK_MENU_SHELL + (gtk_option_menu_get_menu + (GTK_OPTION_MENU(w))), i); + } + gtk_option_menu_set_history(GTK_OPTION_MENU(w), a); + + mapping = FALSE; +} + +void on_titlebar_doubleclick_maximize_activate(GtkMenuItem *w, gpointer data) +{ + if (mapping) return; + + write_doubleclick_action(TITLEBAR_MAXIMIZE); +} + +void on_titlebar_doubleclick_shade_activate(GtkMenuItem *w, gpointer data) +{ + if (mapping) return; + + write_doubleclick_action(TITLEBAR_SHADE); +} + +static void on_titlebar_doubleclick_custom_activate(GtkMenuItem *w, + gpointer data) +{ + if (mapping) return; + + write_doubleclick_action(TITLEBAR_CUSTOM); +} + +void on_doubleclick_time_value_changed(GtkSpinButton *w, gpointer data) +{ + if (mapping) return; + + tree_set_int("mouse/doubleClickTime", + gtk_spin_button_get_value_as_int(w)); +} + +void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data) +{ + if (mapping) return; + + tree_set_int("mouse/dragThreshold", + gtk_spin_button_get_value_as_int(w)); +} + +static gint read_doubleclick_action() +{ + xmlNodePtr n, top, c; + gint max = 0, shade = 0, other = 0; + + top = tree_get_node("mouse/context:name=Titlebar" + "/mousebind:button=Left:action=DoubleClick", NULL); + n = top->children; + + /* save the current state */ + saved_custom = xmlCopyNode(top, 1); + + /* remove the namespace from all the nodes under saved_custom.. + without recursion! */ + c = saved_custom; + while (c) { + xmlSetNs(c, NULL); + if (c->children) + c = c->children; + else if (c->next) + c = c->next; + while (c->parent && !c->parent->next) + c = c->parent; + if (!c->parent) + c = NULL; + } + + while (n) { + if (!xmlStrcmp(n->name, (const xmlChar*)"action")) { + if (parse_attr_contains("ToggleMaximizeFull", n, "name")) + ++max; + else if (parse_attr_contains("ToggleShade", n, "name")) + ++shade; + else + ++other; + + } + n = n->next; + } + + if (max == 1 && shade == 0 && other == 0) + return TITLEBAR_MAXIMIZE; + if (max == 0 && shade == 1 && other == 0) + return TITLEBAR_SHADE; + + return TITLEBAR_CUSTOM; +} + +static void write_doubleclick_action(gint a) +{ + xmlNodePtr n; + + n = tree_get_node("mouse/context:name=Titlebar" + "/mousebind:button=Left:action=DoubleClick", NULL); + + /* remove all children */ + while (n->children) { + xmlUnlinkNode(n->children); + xmlFreeNode(n->children); + } + + if (a == TITLEBAR_MAXIMIZE) { + n = xmlNewChild(n, NULL, "action", NULL); + xmlSetProp(n, "name", "ToggleMaximizeFull"); + } else if (a == TITLEBAR_SHADE) { + n = xmlNewChild(n, NULL, "action", NULL); + xmlSetProp(n, "name", "ToggleShade"); + } else { + xmlNodePtr c = saved_custom->children; + while (c) { + xmlAddChild(n, xmlCopyNode(c, 1)); + c = c->next; + } + } + + tree_apply(); +} diff --git a/src/mouse.h b/src/mouse.h new file mode 100644 index 0000000..739c379 --- /dev/null +++ b/src/mouse.h @@ -0,0 +1,24 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + mouse.h for ObConf, the configuration tool for Openbox + Copyright (c) 2007 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef obconf__mouse_h +#define obconf__mouse_h + +void mouse_setup_tab(); + +#endif diff --git a/src/obconf.glade b/src/obconf.glade index fb7b54c..903848a 100644 --- a/src/obconf.glade +++ b/src/obconf.glade @@ -1699,15 +1699,51 @@ C - The close button True + + + False + True + + + + + + True + Windows + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + 12 + True + False + 18 - + True False 6 - + True <span weight="bold">Mouse Behavior</span> False @@ -1732,13 +1768,13 @@ C - The close button - + True False 0 - + True False @@ -1763,13 +1799,88 @@ C - The close button - + True False 6 - + + True + False + 12 + + + + True + Double-click on the _titlebar: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + dock_position + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + 0 + + + + + + + True + Maximizes the window + True + + + + + + + True + Shades the window + True + + + + + + + + 0 + False + False + + + + + 0 + True + True + + + + + True False 6 @@ -1821,7 +1932,7 @@ C - The close button - + True ms False @@ -1853,7 +1964,7 @@ C - The close button - + True False 6 @@ -1905,7 +2016,7 @@ C - The close button - + True px False @@ -1964,9 +2075,9 @@ C - The close button - + True - Behavior + Mouse False False GTK_JUSTIFY_LEFT diff --git a/src/strings.c b/src/strings.c index 9b459b0..91392f5 100644 --- a/src/strings.c +++ b/src/strings.c @@ -50,13 +50,17 @@ gchar *s = N_("Amount of resistance against other _windows:"); gchar *s = N_("px"); gchar *s = N_("Amount of resistance against screen _edges:"); gchar *s = N_("px"); +gchar *s = N_("Windows"); gchar *s = N_("Mouse Behavior"); gchar *s = N_(" "); +gchar *s = N_("Double-click on the _titlebar:"); +gchar *s = N_("Maximizes the window"); +gchar *s = N_("Shades the window"); gchar *s = N_("Double-_click time:"); gchar *s = N_("ms"); gchar *s = N_("Drag _threshold distance:"); gchar *s = N_("px"); -gchar *s = N_("Behavior"); +gchar *s = N_("Mouse"); gchar *s = N_("Desktops"); gchar *s = N_(" "); gchar *s = N_("_Number of desktops: "); diff --git a/src/behavior.c b/src/windows.c similarity index 78% rename from src/behavior.c rename to src/windows.c index 0fa8e74..898523a 100644 --- a/src/behavior.c +++ b/src/windows.c @@ -1,6 +1,6 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - behavior.c for ObConf, the configuration tool for Openbox + windows.c for ObConf, the configuration tool for Openbox Copyright (c) 2003-2007 Dana Jansens Copyright (c) 2003 Tim Riley @@ -22,9 +22,9 @@ static gboolean mapping = FALSE; -static void behavior_enable_stuff(); +static void windows_enable_stuff(); -void behavior_setup_tab() +void windows_setup_tab() { GtkWidget *w, *w1, *w2; GtkSizeGroup *group; @@ -44,18 +44,6 @@ void behavior_setup_tab() gtk_size_group_add_widget(group, w1); gtk_size_group_add_widget(group, w2); - w1 = get_widget("doubleclick_time"); - w2 = get_widget("drag_threshold"); - group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget(group, w1); - gtk_size_group_add_widget(group, w2); - - w1 = get_widget("doubleclick_time_label"); - w2 = get_widget("drag_threshold_label"); - group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_add_widget(group, w1); - gtk_size_group_add_widget(group, w2); - w = get_widget("focus_mouse"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), tree_get_bool("focus/followMouse", FALSE)); @@ -95,20 +83,12 @@ void behavior_setup_tab() !g_ascii_strcasecmp(s, "UnderMouse")); g_free(s); - w = get_widget("doubleclick_time"); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), - tree_get_int("mouse/doubleClickTime", 200)); - - w = get_widget("drag_threshold"); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), - tree_get_int("mouse/dragThreshold", 3)); - - behavior_enable_stuff(); + windows_enable_stuff(); mapping = FALSE; } -static void behavior_enable_stuff() +static void windows_enable_stuff() { GtkWidget *w; gboolean b; @@ -137,7 +117,7 @@ void on_focus_mouse_toggled(GtkToggleButton *w, gpointer data) b = gtk_toggle_button_get_active(w); tree_set_bool("focus/followMouse", b); - behavior_enable_stuff(); + windows_enable_stuff(); } void on_focus_delay_value_changed(GtkSpinButton *w, gpointer data) @@ -200,19 +180,3 @@ void on_resize_contents_toggled(GtkToggleButton *w, gpointer data) tree_set_bool("resize/drawContents", gtk_toggle_button_get_active(w)); } -void on_doubleclick_time_value_changed(GtkSpinButton *w, gpointer data) -{ - if (mapping) return; - - tree_set_int("mouse/doubleClickTime", - gtk_spin_button_get_value_as_int(w)); -} - -void on_drag_threshold_value_changed(GtkSpinButton *w, gpointer data) -{ - if (mapping) return; - - tree_set_int("mouse/dragThreshold", - gtk_spin_button_get_value_as_int(w)); -} - diff --git a/src/behavior.h b/src/windows.h similarity index 83% rename from src/behavior.h rename to src/windows.h index 3922d42..a8dc378 100644 --- a/src/behavior.h +++ b/src/windows.h @@ -1,6 +1,6 @@ /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- - behavior.h for ObConf, the configuration tool for Openbox + windows.h for ObConf, the configuration tool for Openbox Copyright (c) 2003-2007 Dana Jansens Copyright (c) 2003 Tim Riley @@ -17,9 +17,9 @@ See the COPYING file for a copy of the GNU General Public License. */ -#ifndef obconf__behavior_h -#define obconf__behavior_h +#ifndef obconf__windows_h +#define obconf__windows_h -void behavior_setup_tab(); +void windows_setup_tab(); #endif -- 2.34.1