rename behavior tab to windows.
authorDana Jansens <danakj@orodu.net>
Fri, 1 Jun 2007 01:51:17 +0000 (01:51 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 1 Jun 2007 01:51:17 +0000 (01:51 +0000)
add mouse tab with some super cool code!

Makefile.am
src/main.c
src/mouse.c [new file with mode: 0644]
src/mouse.h [new file with mode: 0644]
src/obconf.glade
src/strings.c
src/windows.c [moved from src/behavior.c with 78% similarity]
src/windows.h [moved from src/behavior.h with 83% similarity]

index f66313d..8cce7b9 100644 (file)
@@ -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 \
index c8008a2..27144d7 100644 (file)
@@ -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 (file)
index 0000000..327680d
--- /dev/null
@@ -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 <openbox/parse.h>
+
+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 (file)
index 0000000..739c379
--- /dev/null
@@ -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
index fb7b54c..903848a 100644 (file)
@@ -1699,15 +1699,51 @@ C - The close button</property>
                  <property name="fill">True</property>
                </packing>
              </child>
+           </widget>
+           <packing>
+             <property name="tab_expand">False</property>
+             <property name="tab_fill">True</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkLabel" id="label22">
+             <property name="visible">True</property>
+             <property name="label" translatable="yes">Windows</property>
+             <property name="use_underline">False</property>
+             <property name="use_markup">False</property>
+             <property name="justify">GTK_JUSTIFY_LEFT</property>
+             <property name="wrap">False</property>
+             <property name="selectable">False</property>
+             <property name="xalign">0.5</property>
+             <property name="yalign">0.5</property>
+             <property name="xpad">0</property>
+             <property name="ypad">0</property>
+             <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+             <property name="width_chars">-1</property>
+             <property name="single_line_mode">False</property>
+             <property name="angle">0</property>
+           </widget>
+           <packing>
+             <property name="type">tab</property>
+           </packing>
+         </child>
+
+         <child>
+           <widget class="GtkVBox" id="vbox56">
+             <property name="border_width">12</property>
+             <property name="visible">True</property>
+             <property name="homogeneous">False</property>
+             <property name="spacing">18</property>
 
              <child>
-               <widget class="GtkVBox" id="vbox43">
+               <widget class="GtkVBox" id="vbox61">
                  <property name="visible">True</property>
                  <property name="homogeneous">False</property>
                  <property name="spacing">6</property>
 
                  <child>
-                   <widget class="GtkLabel" id="label109">
+                   <widget class="GtkLabel" id="label155">
                      <property name="visible">True</property>
                      <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot;&gt;Mouse Behavior&lt;/span&gt;</property>
                      <property name="use_underline">False</property>
@@ -1732,13 +1768,13 @@ C - The close button</property>
                  </child>
 
                  <child>
-                   <widget class="GtkHBox" id="hbox59">
+                   <widget class="GtkHBox" id="hbox84">
                      <property name="visible">True</property>
                      <property name="homogeneous">False</property>
                      <property name="spacing">0</property>
 
                      <child>
-                       <widget class="GtkLabel" id="label110">
+                       <widget class="GtkLabel" id="label156">
                          <property name="visible">True</property>
                          <property name="label" translatable="yes">    </property>
                          <property name="use_underline">False</property>
@@ -1763,13 +1799,88 @@ C - The close button</property>
                      </child>
 
                      <child>
-                       <widget class="GtkVBox" id="vbox44">
+                       <widget class="GtkVBox" id="vbox62">
                          <property name="visible">True</property>
                          <property name="homogeneous">False</property>
                          <property name="spacing">6</property>
 
                          <child>
-                           <widget class="GtkHBox" id="hbox60">
+                           <widget class="GtkHBox" id="hbox87">
+                             <property name="visible">True</property>
+                             <property name="homogeneous">False</property>
+                             <property name="spacing">12</property>
+
+                             <child>
+                               <widget class="GtkLabel" id="label161">
+                                 <property name="visible">True</property>
+                                 <property name="label" translatable="yes">Double-click on the _titlebar:</property>
+                                 <property name="use_underline">True</property>
+                                 <property name="use_markup">False</property>
+                                 <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                 <property name="wrap">False</property>
+                                 <property name="selectable">False</property>
+                                 <property name="xalign">0</property>
+                                 <property name="yalign">0.5</property>
+                                 <property name="xpad">0</property>
+                                 <property name="ypad">0</property>
+                                 <property name="mnemonic_widget">dock_position</property>
+                                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                 <property name="width_chars">-1</property>
+                                 <property name="single_line_mode">False</property>
+                                 <property name="angle">0</property>
+                               </widget>
+                               <packing>
+                                 <property name="padding">0</property>
+                                 <property name="expand">False</property>
+                                 <property name="fill">False</property>
+                               </packing>
+                             </child>
+
+                             <child>
+                               <widget class="GtkOptionMenu" id="titlebar_doubleclick">
+                                 <property name="visible">True</property>
+                                 <property name="can_focus">True</property>
+                                 <property name="history">0</property>
+
+                                 <child>
+                                   <widget class="GtkMenu" id="menu10">
+
+                                     <child>
+                                       <widget class="GtkMenuItem" id="titlebar_doubleclick_maximize">
+                                         <property name="visible">True</property>
+                                         <property name="label" translatable="yes">Maximizes the window</property>
+                                         <property name="use_underline">True</property>
+                                         <signal name="activate" handler="on_titlebar_doubleclick_maximize_activate" last_modification_time="Fri, 01 Jun 2007 00:41:35 GMT"/>
+                                       </widget>
+                                     </child>
+
+                                     <child>
+                                       <widget class="GtkMenuItem" id="titlebar_doubleclick_shade">
+                                         <property name="visible">True</property>
+                                         <property name="label" translatable="yes">Shades the window</property>
+                                         <property name="use_underline">True</property>
+                                         <signal name="activate" handler="on_titlebar_doubleclick_shade_activate" last_modification_time="Fri, 01 Jun 2007 00:41:35 GMT"/>
+                                       </widget>
+                                     </child>
+                                   </widget>
+                                 </child>
+                               </widget>
+                               <packing>
+                                 <property name="padding">0</property>
+                                 <property name="expand">False</property>
+                                 <property name="fill">False</property>
+                               </packing>
+                             </child>
+                           </widget>
+                           <packing>
+                             <property name="padding">0</property>
+                             <property name="expand">True</property>
+                             <property name="fill">True</property>
+                           </packing>
+                         </child>
+
+                         <child>
+                           <widget class="GtkHBox" id="hbox85">
                              <property name="visible">True</property>
                              <property name="homogeneous">False</property>
                              <property name="spacing">6</property>
@@ -1821,7 +1932,7 @@ C - The close button</property>
                              </child>
 
                              <child>
-                               <widget class="GtkLabel" id="doubleclick_time_units_label">
+                               <widget class="GtkLabel" id="label158">
                                  <property name="visible">True</property>
                                  <property name="label" translatable="yes">ms</property>
                                  <property name="use_underline">False</property>
@@ -1853,7 +1964,7 @@ C - The close button</property>
                          </child>
 
                          <child>
-                           <widget class="GtkHBox" id="hbox61">
+                           <widget class="GtkHBox" id="hbox86">
                              <property name="visible">True</property>
                              <property name="homogeneous">False</property>
                              <property name="spacing">6</property>
@@ -1905,7 +2016,7 @@ C - The close button</property>
                              </child>
 
                              <child>
-                               <widget class="GtkLabel" id="drag_threshold_units_label">
+                               <widget class="GtkLabel" id="label160">
                                  <property name="visible">True</property>
                                  <property name="label" translatable="yes">px</property>
                                  <property name="use_underline">False</property>
@@ -1964,9 +2075,9 @@ C - The close button</property>
          </child>
 
          <child>
-           <widget class="GtkLabel" id="label22">
+           <widget class="GtkLabel" id="label118">
              <property name="visible">True</property>
-             <property name="label" translatable="yes">Behavior</property>
+             <property name="label" translatable="yes">Mouse</property>
              <property name="use_underline">False</property>
              <property name="use_markup">False</property>
              <property name="justify">GTK_JUSTIFY_LEFT</property>
index 9b459b0..91392f5 100644 (file)
@@ -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_("<span weight=\"bold\">Mouse Behavior</span>");
 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_("<span weight=\"bold\">Desktops</span>");
 gchar *s = N_("    ");
 gchar *s = N_("_Number of desktops: ");
similarity index 78%
rename from src/behavior.c
rename to src/windows.c
index 0fa8e74..898523a 100644 (file)
@@ -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));
-}
-
similarity index 83%
rename from src/behavior.h
rename to src/windows.h
index 3922d42..a8dc378 100644 (file)
@@ -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