Re: Directional switching

Ian Zimmerman <[email protected]>
Newsgroups gmane.comp.window-managers.openbox
Message-ID <[email protected]>
Here's the final patch, for now.

I addressed your first point about initializing the new config
variables.  I left the other part as it was, for 2 reasons:

1. It still feels marginally more intuitive (for a config file author)
to have 2 parameters, even after sitting on it for a day.

2. I don't know XML Schema, and doing it with a fraction would require
some wrangling in rc.xsd.  The existing fractional element allows
"center" which is not applicable here.

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.

_______________________________________________
openbox mailing list
[email protected]
http://icculus.org/mailman/listinfo/openbox
openbox-directional.patch (text/x-diff, 3.2 KB)
diff --git a/data/rc.xsd b/data/rc.xsd
index 2f90b6e..bad1492 100644
--- a/data/rc.xsd
+++ b/data/rc.xsd
@@ -62,6 +62,8 @@
             <xsd:element minOccurs="0" name="focusDelay" type="xsd:integer"/>
             <xsd:element minOccurs="0" name="raiseOnFocus" type="ob:bool"/>
             <xsd:element minOccurs="0" name="unfocusOnLeave" type="ob:bool"/>
+            <xsd:element minOccurs="0" name="directionalDistanceWeight" type="xsd:integer"/>
+            <xsd:element minOccurs="0" name="directionalAngleWeight" type="xsd:integer"/>
         </xsd:all>
     </xsd:complexType>
     <xsd:complexType name="placement">
diff --git a/openbox/config.c b/openbox/config.c
index 26d3ea0..3fe595f 100644
--- a/openbox/config.c
+++ b/openbox/config.c
@@ -36,6 +36,8 @@ gboolean config_focus_raise;
 gboolean config_focus_last;
 gboolean config_focus_under_mouse;
 gboolean config_unfocus_leave;
+gint config_directional_distance_weight;
+gint config_directional_angle_weight;
 
 ObPlacePolicy  config_place_policy;
 gboolean       config_place_center;
@@ -636,6 +638,10 @@ static void parse_focus(xmlNodePtr node, gpointer d)
         config_focus_under_mouse = obt_xml_node_bool(n);
     if ((n = obt_xml_find_node(node, "unfocusOnLeave")))
         config_unfocus_leave = obt_xml_node_bool(n);
+    if ((n = obt_xml_find_node(node, "directionalDistanceWeight")))
+        config_directional_distance_weight = obt_xml_node_int(n);
+    if ((n = obt_xml_find_node(node, "directionalAngleWeight")))
+        config_directional_angle_weight = obt_xml_node_int(n);
 }
 
 static void parse_placement(xmlNodePtr node, gpointer d)
@@ -1077,6 +1083,8 @@ void config_startup(ObtXmlInst *i)
     config_focus_last = TRUE;
     config_focus_under_mouse = FALSE;
     config_unfocus_leave = FALSE;
+    config_directional_distance_weight = 1;
+    config_directional_angle_weight = 1;
 
     obt_xml_register(i, "focus", parse_focus, NULL);
 
diff --git a/openbox/config.h b/openbox/config.h
index 96a66cf..4796b09 100644
--- a/openbox/config.h
+++ b/openbox/config.h
@@ -85,6 +85,10 @@ extern gboolean config_focus_under_mouse;
 /*! Remove focus from windows when the mouse leaves them
  */
 extern gboolean config_unfocus_leave;
+/*! Weight of distance part of score for directional switching */
+extern gint config_directional_distance_weight;
+/*! Weight of angle part of score for directional switching */
+extern gint config_directional_angle_weight;
 
 /*! The algorithm to use for placing new windows */
 extern ObPlacePolicy config_place_policy;
diff --git a/openbox/focus_cycle.c b/openbox/focus_cycle.c
index de17650..24c0d2a 100644
--- a/openbox/focus_cycle.c
+++ b/openbox/focus_cycle.c
@@ -25,6 +25,7 @@
 #include "screen.h"
 #include "openbox.h"
 #include "debug.h"
+#include "config.h"
 
 #include <X11/Xlib.h>
 #include <glib.h>
@@ -250,7 +251,8 @@ static ObClient *focus_find_directional(ObClient *c, ObDirection dir,
             continue;
 
         /* Calculate score for this window.  The smaller the better. */
-        score = distance + offset;
+        score = (distance * config_directional_distance_weight
+                 + offset * config_directional_angle_weight);
 
         /* windows more than 45 degrees off the direction are
          * heavily penalized and will only be chosen if nothing
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.