]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Implemented <doubleClickTime> in rc.xml
authoralex <alex@compy-sid>
Sun, 29 Aug 2021 22:31:57 +0000 (18:31 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 1 Sep 2021 06:05:37 +0000 (07:05 +0100)
docs/rc.xml.all
include/config/rcxml.h
src/config/rcxml.c
src/cursor.c

index 80eeae053b767b2e3a9ae31092be6c6896494d76..8fa7e1676d84cd2f364c4b8aec9c0c0e75da6841 100644 (file)
@@ -72,6 +72,8 @@
   </keyboard>
 
   <mouse>
+    <!-- time is in ms -->
+    <doubleClickTime>200</doubleClickTime>
     <context name="TitleBar">
       <mousebind button="Left" action="DoubleClick">
         <action name="ToggleMaximize"/>
index e2c60e35ceca94699fd5611eb57e4c61e7d4851f..72bea661534e4a8a0514c8de462cc85a568cd8a2 100644 (file)
@@ -20,6 +20,7 @@ struct rcxml {
        int font_size_menuitem;
        struct wl_list keybinds;
        struct wl_list mousebinds;
+       long doubleclick_time; /* in ms */
 };
 
 extern struct rcxml rc;
index d13db7c0e46e9ecffffd6e6523410ede8891e100..9e6d0298bffd91378b6a1264d06903dd11cd7f3b 100644 (file)
@@ -1,6 +1,7 @@
 #define _POSIX_C_SOURCE 200809L
 #include <assert.h>
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
@@ -374,6 +375,39 @@ traverse_context(xmlNode* node)
        }
 }
 
+static void
+traverse_doubleclick_time(xmlNode* node)
+{
+    /*
+     *     this node
+     *       |
+     *       |
+     *       v
+     * <doubleClickTime>200</doubleClickTime>
+     */
+       for(xmlNode* n = node->children; n && n->name; n = n->next) {
+               if(n->type == XML_TEXT_NODE) {
+                       long doubleclick_time_parsed = strtol((const char*)n->content, NULL, 10);
+
+                       /*
+                        * There are 2 possible sources for a bad doubleclicktime value:
+                        *  - user gave a value of 0 (which doesn't make sense)
+                        *  - user gave a negative value (which doesn't make sense)
+                        *  - user gave a value which strtol couldn't parse
+                        *
+                        *  since strtol() returns 0 on error, all we have to do is check
+                        *  for to see if strtol() returned 0 or less to handle the error
+                        *  cases. in case of error, we just choose not to override the
+                        *  default value and everything should be fine
+                        */
+                       bool valid_doubleclick_time = doubleclick_time_parsed > 0;
+                       if(valid_doubleclick_time) {
+                               rc.doubleclick_time = doubleclick_time_parsed;
+                       }
+               }
+       }
+}
+
 static void
 traverse_mouse(xmlNode* node)
 {
@@ -385,16 +419,19 @@ traverse_mouse(xmlNode* node)
      *    |
      *    v
      * <mouse>
-     *     <context name="TitleBar"> -|
-     *         <mousebind....>           |
-     *           ...                  | -- This node's only supported child is context
-     *         </mousebind>              |
-     *     </context>                -|
+     *     <doubleClickTime>200</doubleClickTime>   ]
+     *     <context name="TitleBar">               -|
+     *         <mousebind....>                         |
+     *           ...                                | -- This node's only supported children
+     *         </mousebind>                            |    are doubleClickTime and context
+     *     </context>                              -|
      * </mouse>
      */
        for(xmlNode* n = node->children; n && n->name; n = n->next) {
                if(strcasecmp((const char*)n->name, "context") == 0) {
                        traverse_context(n);
+               } else if(strcasecmp((const char*)n->name, "doubleClickTime") == 0) {
+                       traverse_doubleclick_time(n);
                } else if(is_ignorable_node(n)) {
                        continue;
                } else {
@@ -454,6 +491,7 @@ rcxml_init()
        rc.corner_radius = 8;
        rc.font_size_activewindow = 10;
        rc.font_size_menuitem = 10;
+       rc.doubleclick_time = 500;
 }
 
 static void
index 5770f5425b0c92d910a4113586ba92db72456198..9801dd41dd87b1f40d53383269dd55270ef1aa39 100644 (file)
@@ -343,7 +343,7 @@ cursor_button(struct wl_listener *listener, void *data)
        desktop_focus_view(&server->seat, view);
        damage_all_outputs(server);
 
-       if (is_double_click(500) && view_area == LAB_SSD_PART_TITLEBAR) {
+       if (is_double_click(rc.doubleclick_time) && view_area == LAB_SSD_PART_TITLEBAR) {
                struct mousebind* mousebind;
                wl_list_for_each_reverse(mousebind, &rc.mousebinds, link) {
                        if( (mousebind->context == MOUSE_CONTEXT_TITLEBAR) &&