From 2df84f6687dfd16aec55206cc672ac0715c7cd68 Mon Sep 17 00:00:00 2001
From: Mark Tiefenbruck <mark@fluxbox.org>
Date: Tue, 5 Aug 2008 17:11:55 -0700
Subject: use the same options in Slit and Toolbar placement menus

---
 data/init.in                   |   5 +-
 src/Slit.cc                    | 263 ++++++++++++++++-------------------------
 src/Slit.hh                    |  17 ++-
 src/Toolbar.hh                 |  10 +-
 src/fluxbox.cc                 |   2 +-
 util/fluxbox-update_configs.cc |  22 ++++
 6 files changed, 140 insertions(+), 179 deletions(-)

diff --git a/data/init.in b/data/init.in
index e1741bb..ef83d41 100644
--- a/data/init.in
+++ b/data/init.in
@@ -1,5 +1,4 @@
-session.screen0.slit.placement:	BottomRight
-session.screen0.slit.direction:	Vertical
+session.screen0.slit.placement:	RightBottom
 session.screen0.slit.onTop:	False
 session.screen0.slit.autoHide:	False
 session.screen0.tab.placement:	Top
@@ -30,4 +29,4 @@ session.colorsPerChannel:	4
 session.doubleClickInterval:	250
 session.cacheMax:	200
 session.imageDither:	True
-session.configVersion:	8
+session.configVersion:	9
diff --git a/src/Slit.cc b/src/Slit.cc
index 20b86d6..80dca0d 100644
--- a/src/Slit.cc
+++ b/src/Slit.cc
@@ -93,8 +93,7 @@ template<>
 void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) {
     if (strcasecmp(strval, "TopLeft")==0)
         m_value = Slit::TOPLEFT;
-    else if (strcasecmp(strval, "LeftCenter")==0
-             || strcasecmp(strval, "CenterLeft")==0)
+    else if (strcasecmp(strval, "LeftCenter")==0)
         m_value = Slit::LEFTCENTER;
     else if (strcasecmp(strval, "BottomLeft")==0)
         m_value = Slit::BOTTOMLEFT;
@@ -104,21 +103,18 @@ void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) {
         m_value = Slit::BOTTOMCENTER;
     else if (strcasecmp(strval, "TopRight")==0)
         m_value = Slit::TOPRIGHT;
-    else if (strcasecmp(strval, "RightCenter")==0
-             || strcasecmp(strval, "CenterRight")==0)
+    else if (strcasecmp(strval, "RightCenter")==0)
         m_value = Slit::RIGHTCENTER;
     else if (strcasecmp(strval, "BottomRight")==0)
         m_value = Slit::BOTTOMRIGHT;
-    else
-        setDefaultValue();
-}
-
-template<>
-void FbTk::Resource<Slit::Direction>::setFromString(const char *strval) {
-    if (strcasecmp(strval, "Vertical") == 0)
-        m_value = Slit::VERTICAL;
-    else if (strcasecmp(strval, "Horizontal") == 0)
-        m_value = Slit::HORIZONTAL;
+    else if (strcasecmp(strval, "LeftTop")==0)
+        m_value = Slit::LEFTTOP;
+    else if (strcasecmp(strval, "LeftBottom")==0)
+        m_value = Slit::LEFTBOTTOM;
+    else if (strcasecmp(strval, "RightTop")==0)
+        m_value = Slit::RIGHTTOP;
+    else if (strcasecmp(strval, "RightBottom")==0)
+        m_value = Slit::RIGHTBOTTOM;
     else
         setDefaultValue();
 }
@@ -150,24 +146,23 @@ string FbTk::Resource<Slit::Placement>::getString() const {
     case Slit::BOTTOMRIGHT:
         return string("BottomRight");
         break;
-    }
-    //default string
-    return string("BottomRight");
-}
-
-template<>
-string FbTk::Resource<Slit::Direction>::getString() const {
-    switch (m_value) {
-    case Slit::VERTICAL:
-        return string("Vertical");
+    case Slit::LEFTTOP:
+        return string("LeftTop");
         break;
-    case Slit::HORIZONTAL:
-        return string("Horizontal");
+    case Slit::RIGHTTOP:
+        return string("RightTop");
+        break;
+    case Slit::LEFTBOTTOM:
+        return string("LeftBottom");
+        break;
+    case Slit::RIGHTBOTTOM:
+        return string("RightBottom");
         break;
     }
-    // default string
-    return string("Vertical");
+    //default string
+    return string("RightBottom");
 }
+
 } // end namespace FbTk
 namespace {
 
@@ -202,41 +197,6 @@ private:
     SlitClient &m_client;
 };
 
-class SlitDirMenuItem: public FbTk::MenuItem {
-public:
-    SlitDirMenuItem(const FbTk::FbString &label, Slit &slit, FbTk::RefCount<FbTk::Command<void> > &cmd)
-        :FbTk::MenuItem(label,cmd),
-         m_slit(slit),
-         m_label(label) {
-        setLabel(m_label); // update label
-        setCloseOnClick(false);
-    }
-
-    void click(int button, int time, unsigned int mods) {
-        // toggle direction
-        if (m_slit.direction() == Slit::HORIZONTAL)
-            m_slit.setDirection(Slit::VERTICAL);
-        else
-            m_slit.setDirection(Slit::HORIZONTAL);
-        setLabel(m_label);
-        FbTk::MenuItem::click(button, time, mods);
-    }
-
-    void setLabel(const FbTk::FbString &label) {
-        _FB_USES_NLS;
-        m_label = (label);
-        string reallabel = m_label + " " +
-            ( m_slit.direction() == Slit::HORIZONTAL ?
-
-              _FB_XTEXT(Align, Horizontal, "Horizontal", "Horizontal"):
-              _FB_XTEXT(Align, Vertical,   "Vertical",   "Vertical"));
-        FbTk::MenuItem::setLabel(reallabel);
-    }
-private:
-    Slit &m_slit;
-    string m_label;
-};
-
 class PlaceSlitMenuItem: public FbTk::RadioMenuItem {
 public:
     PlaceSlitMenuItem(const FbTk::FbString &label, Slit &slit, Slit::Placement place, FbTk::RefCount<FbTk::Command<void> > &cmd):
@@ -290,10 +250,8 @@ Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename)
       // TODO: this resource name must change
       m_rc_maximize_over(scr.resourceManager(), false,
                          scr.name() + ".slit.maxOver", scr.altName() + ".Slit.MaxOver"),
-      m_rc_placement(scr.resourceManager(), BOTTOMRIGHT,
+      m_rc_placement(scr.resourceManager(), RIGHTBOTTOM,
                      scr.name() + ".slit.placement", scr.altName() + ".Slit.Placement"),
-      m_rc_direction(scr.resourceManager(), VERTICAL,
-                     scr.name() + ".slit.direction", scr.altName() + ".Slit.Direction"),
       m_rc_alpha(scr.resourceManager(), 255,
                  scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"),
       m_rc_on_head(scr.resourceManager(), 0,
@@ -386,46 +344,40 @@ void Slit::updateStrut() {
     int left = 0, right = 0, top = 0, bottom = 0;
     switch (placement()) {
     case TOPLEFT:
-        if (direction() == HORIZONTAL)
-            top = height() + 2 * bw;
-        else
-            left = width() + 2 * bw;
+        top = height() + 2 * bw;
+        break;
+    case LEFTTOP:
+        left = width() + 2 * bw;
         break;
     case TOPCENTER:
-        if (direction() == HORIZONTAL)
-            top = height() + 2 * bw;
+        top = height() + 2 * bw;
         break;
     case TOPRIGHT:
-        if (direction() == HORIZONTAL)
-            top = height() + 2 * bw;
-        else
-            right = width() + 2 * bw;
+        top = height() + 2 * bw;
+        break;
+    case RIGHTTOP:
+        right = width() + 2 * bw;
         break;
     case BOTTOMLEFT:
-        if (direction() == HORIZONTAL)
-            bottom = height() + 2 * bw;
-        else
-            left = width() + 2 * bw;
+        bottom = height() + 2 * bw;
+        break;
+    case LEFTBOTTOM:
+        left = width() + 2 * bw;
         break;
     case BOTTOMCENTER:
-        // would be strange to have it request size on vertical direction
-        // each time we add a client
-        if (direction() == HORIZONTAL)
-            bottom = height() + 2 * bw;
+        bottom = height() + 2 * bw;
         break;
     case BOTTOMRIGHT:
-        if (direction() == HORIZONTAL)
-            bottom = height() + 2 * bw;
-        else
-            right = width() + 2 * bw;
+        bottom = height() + 2 * bw;
+        break;
+    case RIGHTBOTTOM:
+        right = width() + 2 * bw;
         break;
     case LEFTCENTER:
-        if (direction() == VERTICAL)
-            left = width() + 2 * bw;
+        left = width() + 2 * bw;
         break;
     case RIGHTCENTER:
-        if (direction() == VERTICAL)
-            right = width() + 2 * bw;
+        right = width() + 2 * bw;
         break;
     }
 
@@ -551,11 +503,6 @@ void Slit::addClient(Window w) {
 
 }
 
-void Slit::setDirection(Direction dir) {
-    *m_rc_direction = dir;
-    reconfigure();
-}
-
 void Slit::setPlacement(Placement place) {
     *m_rc_placement = place;
     reconfigure();
@@ -636,11 +583,15 @@ void Slit::reconfigure() {
     const int bevel_width = theme()->bevelWidth();
     // determine width or height increase
     bool height_inc = false;
-    switch (direction()) {
-    case VERTICAL:
+    switch (placement()) {
+    case LEFTTOP:
+    case RIGHTTOP:
+    case LEFTCENTER:
+    case RIGHTCENTER:
+    case LEFTBOTTOM:
+    case RIGHTBOTTOM:
         height_inc = true;
-        break;
-    case HORIZONTAL: // already false
+    default:
         break;
     }
 
@@ -724,19 +675,10 @@ void Slit::reconfigure() {
         show();
 
     int x = 0, y = 0;
-    height_inc = false;
-    switch (direction()) {
-    case VERTICAL:
-        x = 0;
+    if (height_inc)
         y = bevel_width;
-        height_inc = true;
-        break;
-
-    case HORIZONTAL:
+    else
         x = bevel_width;
-        y = 0;
-        break;
-    }
 
     client_it = m_client_list.begin();
     for (; client_it != client_it_end; ++client_it) {
@@ -826,90 +768,86 @@ void Slit::reposition() {
     case TOPLEFT:
         frame.x = head_x;
         frame.y = head_y;
-        if (direction() == VERTICAL) {
-            frame.x_hidden = bevel_width -
-                border_width - frame.width;
-            frame.y_hidden = head_y;
-        } else {
-            frame.x_hidden = head_x;
-            frame.y_hidden = bevel_width -
-                border_width - frame.height;
-        }
+        frame.x_hidden = head_x;
+        frame.y_hidden = bevel_width - border_width - frame.height;
+        break;
+
+    case LEFTTOP:
+        frame.x = head_x;
+        frame.y = head_y;
+        frame.x_hidden = bevel_width - border_width - frame.width;
+        frame.y_hidden = head_y;
         break;
 
     case LEFTCENTER:
         frame.x = head_x;
         frame.y = head_y + (head_h - frame.height) / 2;
-        frame.x_hidden = head_x + bevel_width -
-            border_width - frame.width;
+        frame.x_hidden = head_x + bevel_width - border_width - frame.width;
         frame.y_hidden = frame.y;
         break;
 
     case BOTTOMLEFT:
         frame.x = head_x;
         frame.y = head_y + head_h - frame.height - border_width*2;
-        if (direction() == VERTICAL) {
-            frame.x_hidden = head_x + bevel_width -
-                border_width - frame.width;
-            frame.y_hidden = frame.y;
-        } else {
-            frame.x_hidden = head_x;
-            frame.y_hidden = head_y + head_h -
-                bevel_width - border_width;
-        }
+        frame.x_hidden = head_x;
+        frame.y_hidden = head_y + head_h - bevel_width - border_width;
+        break;
+
+    case LEFTBOTTOM:
+        frame.x = head_x;
+        frame.y = head_y + head_h - frame.height - border_width*2;
+        frame.x_hidden = head_x + bevel_width - border_width - frame.width;
+        frame.y_hidden = frame.y;
         break;
 
     case TOPCENTER:
         frame.x = head_x + ((head_w - frame.width) / 2);
         frame.y = head_y;
         frame.x_hidden = frame.x;
-        frame.y_hidden = head_y + bevel_width -
-            border_width - frame.height;
+        frame.y_hidden = head_y + bevel_width - border_width - frame.height;
         break;
 
     case BOTTOMCENTER:
         frame.x = head_x + ((head_w - frame.width) / 2);
         frame.y = head_y + head_h - frame.height - border_width*2;
         frame.x_hidden = frame.x;
-        frame.y_hidden = head_y + head_h -
-            bevel_width - border_width;
+        frame.y_hidden = head_y + head_h - bevel_width - border_width;
         break;
 
     case TOPRIGHT:
         frame.x = head_x + head_w - frame.width - border_width*2;
         frame.y = head_y;
-        if (direction() == VERTICAL) {
-            frame.x_hidden = head_x + head_w -
-                bevel_width - border_width;
-            frame.y_hidden = head_y;
-        } else {
-            frame.x_hidden = frame.x;
-            frame.y_hidden = head_y + bevel_width -
-                border_width - frame.height;
-        }
+        frame.x_hidden = frame.x;
+        frame.y_hidden = head_y + bevel_width - border_width - frame.height;
+        break;
+
+    case RIGHTTOP:
+        frame.x = head_x + head_w - frame.width - border_width*2;
+        frame.y = head_y;
+        frame.x_hidden = head_x + head_w - bevel_width - border_width;
+        frame.y_hidden = head_y;
         break;
 
     case RIGHTCENTER:
-    default:
         frame.x = head_x + head_w - frame.width - border_width*2;
         frame.y = head_y + ((head_h - frame.height) / 2);
-        frame.x_hidden = head_x + head_w -
-            bevel_width - border_width;
+        frame.x_hidden = head_x + head_w - bevel_width - border_width;
         frame.y_hidden = frame.y;
         break;
 
     case BOTTOMRIGHT:
         frame.x = head_x + head_w - frame.width - border_width*2;
         frame.y = head_y + head_h - frame.height - border_width*2;
-        if (direction() == VERTICAL) {
-            frame.x_hidden = head_x + head_w -
-                bevel_width - border_width;
-            frame.y_hidden = frame.y;
-        } else {
-            frame.x_hidden = frame.x;
-            frame.y_hidden = head_y + head_h -
-                bevel_width - border_width;
-        }
+        frame.x_hidden = frame.x;
+        frame.y_hidden = head_y + head_h - bevel_width - border_width;
+        break;
+
+    case RIGHTBOTTOM:
+    default:
+        frame.x = head_x + head_w - frame.width - border_width*2;
+        frame.y = head_y + head_h - frame.height - border_width*2;
+        frame.x_hidden = head_x + head_w - bevel_width - border_width;
+        frame.y_hidden = frame.y;
         break;
     }
 
@@ -1292,9 +1230,6 @@ void Slit::setupMenu() {
 
     m_slitmenu.insert(alpha_menuitem);
 
-    m_slitmenu.insert(new SlitDirMenuItem(_FB_XTEXT(Slit, Direction, "Slit Direction:", "Orientation of slit"),
-                                          *this,
-                                          save_and_reconfigure));
     m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu);
     m_slitmenu.updateMenu();
 
@@ -1311,18 +1246,24 @@ void Slit::setupMenu() {
 
     // menu is 3 wide, 5 down
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), Slit::TOPLEFT));
+    place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), Slit::LEFTTOP));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), Slit::LEFTCENTER));
+    place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), Slit::LEFTBOTTOM));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), Slit::BOTTOMLEFT));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), Slit::TOPCENTER));
     place_menu.push_back(PlacementP("", Slit::TOPLEFT));
+    place_menu.push_back(PlacementP("", Slit::TOPLEFT));
+    place_menu.push_back(PlacementP("", Slit::TOPLEFT));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), Slit::BOTTOMCENTER));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), Slit::TOPRIGHT));
+    place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), Slit::RIGHTTOP));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), Slit::RIGHTCENTER));
+    place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), Slit::RIGHTBOTTOM));
     place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Slit::BOTTOMRIGHT));
 
 
     // create items in sub menu
-    for (size_t i=0; i<9; ++i) {
+    for (size_t i=0; i<15; ++i) {
         const FbTk::FbString &str = place_menu.front().first;
         Slit::Placement placement = place_menu.front().second;
 
diff --git a/src/Slit.hh b/src/Slit.hh
index a7f8e40..19e4698 100644
--- a/src/Slit.hh
+++ b/src/Slit.hh
@@ -55,21 +55,22 @@ class Slit: public FbTk::EventHandler, public FbTk::Observer, public LayerObject
 public:
     typedef std::list<SlitClient *> SlitClients;
     /**
-       Client alignment
-    */
-    enum Direction { VERTICAL = 1, HORIZONTAL };
-    /**
        Placement on screen
     */
-    enum Placement { TOPLEFT = 1, LEFTCENTER, BOTTOMLEFT, TOPCENTER, BOTTOMCENTER,
-           TOPRIGHT, RIGHTCENTER, BOTTOMRIGHT };
+    enum Placement {
+        // top and bottom placement
+        TOPLEFT = 1, TOPCENTER, TOPRIGHT,
+        BOTTOMLEFT, BOTTOMCENTER, BOTTOMRIGHT,
+        // left and right placement
+        LEFTBOTTOM, LEFTCENTER, LEFTTOP,
+        RIGHTBOTTOM, RIGHTCENTER, RIGHTTOP
+    };
 
     Slit(BScreen &screen, FbTk::XLayer &layer, const char *filename = 0);
     virtual ~Slit();
 
     void show() { frame.window.show(); m_visible = true; }
     void hide() { frame.window.hide(); m_visible = false; }
-    void setDirection(Direction dir);
     void setPlacement(Placement place);
     void addClient(Window clientwin);
     void removeClient(Window clientwin, bool remap = true);
@@ -113,7 +114,6 @@ public:
     bool isHidden() const { return m_hidden; }
     bool acceptKdeDockapp() const { return *m_rc_kde_dockapp; }
     bool doAutoHide() const { return *m_rc_auto_hide; }
-    Direction direction() const { return *m_rc_direction; }
     Placement placement() const { return *m_rc_placement; }
     int getOnHead() const { return *m_rc_on_head; }
     void saveOnHead(int head);
@@ -178,7 +178,6 @@ private:
 
     FbTk::Resource<bool> m_rc_kde_dockapp, m_rc_auto_hide, m_rc_maximize_over;
     FbTk::Resource<Slit::Placement> m_rc_placement;
-    FbTk::Resource<Slit::Direction> m_rc_direction;
     FbTk::Resource<int> m_rc_alpha, m_rc_on_head;
     FbTk::Resource<class Layer> m_rc_layernum;
 };
diff --git a/src/Toolbar.hh b/src/Toolbar.hh
index c68210f..100b38b 100644
--- a/src/Toolbar.hh
+++ b/src/Toolbar.hh
@@ -61,13 +61,13 @@ class Toolbar: public FbTk::EventHandler,
 public:
 
     /// Toolbar placement on the screen
-    enum Placement{
+    enum Placement {
         // top and bottom placement
-        TOPLEFT = 1, BOTTOMLEFT, TOPCENTER,
-        BOTTOMCENTER, TOPRIGHT, BOTTOMRIGHT,
+        TOPLEFT = 1, TOPCENTER, TOPRIGHT,
+        BOTTOMLEFT, BOTTOMCENTER, BOTTOMRIGHT,
         // left and right placement
-        LEFTCENTER, LEFTBOTTOM, LEFTTOP,
-        RIGHTCENTER, RIGHTBOTTOM, RIGHTTOP
+        LEFTBOTTOM, LEFTCENTER, LEFTTOP,
+        RIGHTBOTTOM, RIGHTCENTER, RIGHTTOP
     };
 
     /// Create a toolbar on the screen with specific width
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index ae27828..f6c9f25 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -594,7 +594,7 @@ void Fluxbox::setupConfigFiles() {
     if (create_windowmenu)
         FbTk::FileUtil::copyFile(DEFAULT_WINDOWMENU, windowmenu_file.c_str());
 
-#define CONFIG_VERSION 8
+#define CONFIG_VERSION 9
     FbTk::Resource<int> config_version(m_resourcemanager, 0,
             "session.configVersion", "Session.ConfigVersion");
     if (*config_version < CONFIG_VERSION) {
diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc
index 365136b..0105c18 100644
--- a/util/fluxbox-update_configs.cc
+++ b/util/fluxbox-update_configs.cc
@@ -301,6 +301,28 @@ int run_updates(int old_version, FbTk::ResourceManager &rm) {
         new_version = 8;
     }
 
+    if (old_version < 9) { // change format of slit placement menu
+        FbTk::Resource<string> *placement =
+            new FbTk::Resource<string>(rm, "BottomRight",
+                                       "session.screen0.slit.placement",
+                                       "Session.Screen0.Slit.Placement");
+        FbTk::Resource<string> *direction =
+            new FbTk::Resource<string>(rm, "Vertical",
+                                       "session.screen0.slit.direction",
+                                       "Session.Screen0.Slit.Direction");
+        if (strcasecmp((**direction).c_str(), "vertical") == 0) {
+            if (strcasecmp((**placement).c_str(), "BottomRight") == 0)
+                *placement = "RightBottom";
+            else if (strcasecmp((**placement).c_str(), "BottomLeft") == 0)
+                *placement = "LeftBottom";
+            else if (strcasecmp((**placement).c_str(), "TopRight") == 0)
+                *placement = "RightTop";
+            else if (strcasecmp((**placement).c_str(), "TopLeft") == 0)
+                *placement = "LeftTop";
+        }
+        new_version = 9;
+    }
+
     return new_version;
 }
 
-- 
cgit v0.11.2