aboutsummaryrefslogtreecommitdiff
path: root/src/Slit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Slit.cc')
-rw-r--r--src/Slit.cc272
1 files changed, 107 insertions, 165 deletions
diff --git a/src/Slit.cc b/src/Slit.cc
index ecd8280..80dca0d 100644
--- a/src/Slit.cc
+++ b/src/Slit.cc
@@ -57,6 +57,7 @@
57#include "FbTk/I18n.hh" 57#include "FbTk/I18n.hh"
58#include "FbTk/BoolMenuItem.hh" 58#include "FbTk/BoolMenuItem.hh"
59#include "FbTk/IntMenuItem.hh" 59#include "FbTk/IntMenuItem.hh"
60#include "FbTk/RadioMenuItem.hh"
60 61
61#ifdef HAVE_SYS_STAT_H 62#ifdef HAVE_SYS_STAT_H
62#include <sys/types.h> 63#include <sys/types.h>
@@ -92,8 +93,7 @@ template<>
92void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) { 93void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) {
93 if (strcasecmp(strval, "TopLeft")==0) 94 if (strcasecmp(strval, "TopLeft")==0)
94 m_value = Slit::TOPLEFT; 95 m_value = Slit::TOPLEFT;
95 else if (strcasecmp(strval, "LeftCenter")==0 96 else if (strcasecmp(strval, "LeftCenter")==0)
96 || strcasecmp(strval, "CenterLeft")==0)
97 m_value = Slit::LEFTCENTER; 97 m_value = Slit::LEFTCENTER;
98 else if (strcasecmp(strval, "BottomLeft")==0) 98 else if (strcasecmp(strval, "BottomLeft")==0)
99 m_value = Slit::BOTTOMLEFT; 99 m_value = Slit::BOTTOMLEFT;
@@ -103,21 +103,18 @@ void FbTk::Resource<Slit::Placement>::setFromString(const char *strval) {
103 m_value = Slit::BOTTOMCENTER; 103 m_value = Slit::BOTTOMCENTER;
104 else if (strcasecmp(strval, "TopRight")==0) 104 else if (strcasecmp(strval, "TopRight")==0)
105 m_value = Slit::TOPRIGHT; 105 m_value = Slit::TOPRIGHT;
106 else if (strcasecmp(strval, "RightCenter")==0 106 else if (strcasecmp(strval, "RightCenter")==0)
107 || strcasecmp(strval, "CenterRight")==0)
108 m_value = Slit::RIGHTCENTER; 107 m_value = Slit::RIGHTCENTER;
109 else if (strcasecmp(strval, "BottomRight")==0) 108 else if (strcasecmp(strval, "BottomRight")==0)
110 m_value = Slit::BOTTOMRIGHT; 109 m_value = Slit::BOTTOMRIGHT;
111 else 110 else if (strcasecmp(strval, "LeftTop")==0)
112 setDefaultValue(); 111 m_value = Slit::LEFTTOP;
113} 112 else if (strcasecmp(strval, "LeftBottom")==0)
114 113 m_value = Slit::LEFTBOTTOM;
115template<> 114 else if (strcasecmp(strval, "RightTop")==0)
116void FbTk::Resource<Slit::Direction>::setFromString(const char *strval) { 115 m_value = Slit::RIGHTTOP;
117 if (strcasecmp(strval, "Vertical") == 0) 116 else if (strcasecmp(strval, "RightBottom")==0)
118 m_value = Slit::VERTICAL; 117 m_value = Slit::RIGHTBOTTOM;
119 else if (strcasecmp(strval, "Horizontal") == 0)
120 m_value = Slit::HORIZONTAL;
121 else 118 else
122 setDefaultValue(); 119 setDefaultValue();
123} 120}
@@ -149,24 +146,23 @@ string FbTk::Resource<Slit::Placement>::getString() const {
149 case Slit::BOTTOMRIGHT: 146 case Slit::BOTTOMRIGHT:
150 return string("BottomRight"); 147 return string("BottomRight");
151 break; 148 break;
152 } 149 case Slit::LEFTTOP:
153 //default string 150 return string("LeftTop");
154 return string("BottomRight");
155}
156
157template<>
158string FbTk::Resource<Slit::Direction>::getString() const {
159 switch (m_value) {
160 case Slit::VERTICAL:
161 return string("Vertical");
162 break; 151 break;
163 case Slit::HORIZONTAL: 152 case Slit::RIGHTTOP:
164 return string("Horizontal"); 153 return string("RightTop");
154 break;
155 case Slit::LEFTBOTTOM:
156 return string("LeftBottom");
157 break;
158 case Slit::RIGHTBOTTOM:
159 return string("RightBottom");
165 break; 160 break;
166 } 161 }
167 // default string 162 //default string
168 return string("Vertical"); 163 return string("RightBottom");
169} 164}
165
170} // end namespace FbTk 166} // end namespace FbTk
171namespace { 167namespace {
172 168
@@ -201,51 +197,16 @@ private:
201 SlitClient &m_client; 197 SlitClient &m_client;
202}; 198};
203 199
204class SlitDirMenuItem: public FbTk::MenuItem { 200class PlaceSlitMenuItem: public FbTk::RadioMenuItem {
205public:
206 SlitDirMenuItem(const FbTk::FbString &label, Slit &slit, FbTk::RefCount<FbTk::Command<void> > &cmd)
207 :FbTk::MenuItem(label,cmd),
208 m_slit(slit),
209 m_label(label) {
210 setLabel(m_label); // update label
211 setCloseOnClick(false);
212 }
213
214 void click(int button, int time, unsigned int mods) {
215 // toggle direction
216 if (m_slit.direction() == Slit::HORIZONTAL)
217 m_slit.setDirection(Slit::VERTICAL);
218 else
219 m_slit.setDirection(Slit::HORIZONTAL);
220 setLabel(m_label);
221 FbTk::MenuItem::click(button, time, mods);
222 }
223
224 void setLabel(const FbTk::FbString &label) {
225 _FB_USES_NLS;
226 m_label = (label);
227 string reallabel = m_label + " " +
228 ( m_slit.direction() == Slit::HORIZONTAL ?
229
230 _FB_XTEXT(Align, Horizontal, "Horizontal", "Horizontal"):
231 _FB_XTEXT(Align, Vertical, "Vertical", "Vertical"));
232 FbTk::MenuItem::setLabel(reallabel);
233 }
234private:
235 Slit &m_slit;
236 string m_label;
237};
238
239class PlaceSlitMenuItem: public FbTk::MenuItem {
240public: 201public:
241 PlaceSlitMenuItem(const FbTk::FbString &label, Slit &slit, Slit::Placement place, FbTk::RefCount<FbTk::Command<void> > &cmd): 202 PlaceSlitMenuItem(const FbTk::FbString &label, Slit &slit, Slit::Placement place, FbTk::RefCount<FbTk::Command<void> > &cmd):
242 FbTk::MenuItem(label, cmd), m_slit(slit), m_place(place) { 203 FbTk::RadioMenuItem(label, cmd), m_slit(slit), m_place(place) {
243 setCloseOnClick(false); 204 setCloseOnClick(false);
244 } 205 }
245 bool isEnabled() const { return m_slit.placement() != m_place; } 206 bool isSelected() const { return m_slit.placement() == m_place; }
246 void click(int button, int time, unsigned int mods) { 207 void click(int button, int time, unsigned int mods) {
247 m_slit.setPlacement(m_place); 208 m_slit.setPlacement(m_place);
248 FbTk::MenuItem::click(button, time, mods); 209 FbTk::RadioMenuItem::click(button, time, mods);
249 } 210 }
250private: 211private:
251 Slit &m_slit; 212 Slit &m_slit;
@@ -289,10 +250,8 @@ Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename)
289 // TODO: this resource name must change 250 // TODO: this resource name must change
290 m_rc_maximize_over(scr.resourceManager(), false, 251 m_rc_maximize_over(scr.resourceManager(), false,
291 scr.name() + ".slit.maxOver", scr.altName() + ".Slit.MaxOver"), 252 scr.name() + ".slit.maxOver", scr.altName() + ".Slit.MaxOver"),
292 m_rc_placement(scr.resourceManager(), BOTTOMRIGHT, 253 m_rc_placement(scr.resourceManager(), RIGHTBOTTOM,
293 scr.name() + ".slit.placement", scr.altName() + ".Slit.Placement"), 254 scr.name() + ".slit.placement", scr.altName() + ".Slit.Placement"),
294 m_rc_direction(scr.resourceManager(), VERTICAL,
295 scr.name() + ".slit.direction", scr.altName() + ".Slit.Direction"),
296 m_rc_alpha(scr.resourceManager(), 255, 255 m_rc_alpha(scr.resourceManager(), 255,
297 scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"), 256 scr.name() + ".slit.alpha", scr.altName() + ".Slit.Alpha"),
298 m_rc_on_head(scr.resourceManager(), 0, 257 m_rc_on_head(scr.resourceManager(), 0,
@@ -385,46 +344,40 @@ void Slit::updateStrut() {
385 int left = 0, right = 0, top = 0, bottom = 0; 344 int left = 0, right = 0, top = 0, bottom = 0;
386 switch (placement()) { 345 switch (placement()) {
387 case TOPLEFT: 346 case TOPLEFT:
388 if (direction() == HORIZONTAL) 347 top = height() + 2 * bw;
389 top = height() + 2 * bw; 348 break;
390 else 349 case LEFTTOP:
391 left = width() + 2 * bw; 350 left = width() + 2 * bw;
392 break; 351 break;
393 case TOPCENTER: 352 case TOPCENTER:
394 if (direction() == HORIZONTAL) 353 top = height() + 2 * bw;
395 top = height() + 2 * bw;
396 break; 354 break;
397 case TOPRIGHT: 355 case TOPRIGHT:
398 if (direction() == HORIZONTAL) 356 top = height() + 2 * bw;
399 top = height() + 2 * bw; 357 break;
400 else 358 case RIGHTTOP:
401 right = width() + 2 * bw; 359 right = width() + 2 * bw;
402 break; 360 break;
403 case BOTTOMLEFT: 361 case BOTTOMLEFT:
404 if (direction() == HORIZONTAL) 362 bottom = height() + 2 * bw;
405 bottom = height() + 2 * bw; 363 break;
406 else 364 case LEFTBOTTOM:
407 left = width() + 2 * bw; 365 left = width() + 2 * bw;
408 break; 366 break;
409 case BOTTOMCENTER: 367 case BOTTOMCENTER:
410 // would be strange to have it request size on vertical direction 368 bottom = height() + 2 * bw;
411 // each time we add a client
412 if (direction() == HORIZONTAL)
413 bottom = height() + 2 * bw;
414 break; 369 break;
415 case BOTTOMRIGHT: 370 case BOTTOMRIGHT:
416 if (direction() == HORIZONTAL) 371 bottom = height() + 2 * bw;
417 bottom = height() + 2 * bw; 372 break;
418 else 373 case RIGHTBOTTOM:
419 right = width() + 2 * bw; 374 right = width() + 2 * bw;
420 break; 375 break;
421 case LEFTCENTER: 376 case LEFTCENTER:
422 if (direction() == VERTICAL) 377 left = width() + 2 * bw;
423 left = width() + 2 * bw;
424 break; 378 break;
425 case RIGHTCENTER: 379 case RIGHTCENTER:
426 if (direction() == VERTICAL) 380 right = width() + 2 * bw;
427 right = width() + 2 * bw;
428 break; 381 break;
429 } 382 }
430 383
@@ -550,11 +503,6 @@ void Slit::addClient(Window w) {
550 503
551} 504}
552 505
553void Slit::setDirection(Direction dir) {
554 *m_rc_direction = dir;
555 reconfigure();
556}
557
558void Slit::setPlacement(Placement place) { 506void Slit::setPlacement(Placement place) {
559 *m_rc_placement = place; 507 *m_rc_placement = place;
560 reconfigure(); 508 reconfigure();
@@ -635,11 +583,15 @@ void Slit::reconfigure() {
635 const int bevel_width = theme()->bevelWidth(); 583 const int bevel_width = theme()->bevelWidth();
636 // determine width or height increase 584 // determine width or height increase
637 bool height_inc = false; 585 bool height_inc = false;
638 switch (direction()) { 586 switch (placement()) {
639 case VERTICAL: 587 case LEFTTOP:
588 case RIGHTTOP:
589 case LEFTCENTER:
590 case RIGHTCENTER:
591 case LEFTBOTTOM:
592 case RIGHTBOTTOM:
640 height_inc = true; 593 height_inc = true;
641 break; 594 default:
642 case HORIZONTAL: // already false
643 break; 595 break;
644 } 596 }
645 597
@@ -723,19 +675,10 @@ void Slit::reconfigure() {
723 show(); 675 show();
724 676
725 int x = 0, y = 0; 677 int x = 0, y = 0;
726 height_inc = false; 678 if (height_inc)
727 switch (direction()) {
728 case VERTICAL:
729 x = 0;
730 y = bevel_width; 679 y = bevel_width;
731 height_inc = true; 680 else
732 break;
733
734 case HORIZONTAL:
735 x = bevel_width; 681 x = bevel_width;
736 y = 0;
737 break;
738 }
739 682
740 client_it = m_client_list.begin(); 683 client_it = m_client_list.begin();
741 for (; client_it != client_it_end; ++client_it) { 684 for (; client_it != client_it_end; ++client_it) {
@@ -825,90 +768,86 @@ void Slit::reposition() {
825 case TOPLEFT: 768 case TOPLEFT:
826 frame.x = head_x; 769 frame.x = head_x;
827 frame.y = head_y; 770 frame.y = head_y;
828 if (direction() == VERTICAL) { 771 frame.x_hidden = head_x;
829 frame.x_hidden = bevel_width - 772 frame.y_hidden = bevel_width - border_width - frame.height;
830 border_width - frame.width; 773 break;
831 frame.y_hidden = head_y; 774
832 } else { 775 case LEFTTOP:
833 frame.x_hidden = head_x; 776 frame.x = head_x;
834 frame.y_hidden = bevel_width - 777 frame.y = head_y;
835 border_width - frame.height; 778 frame.x_hidden = bevel_width - border_width - frame.width;
836 } 779 frame.y_hidden = head_y;
837 break; 780 break;
838 781
839 case LEFTCENTER: 782 case LEFTCENTER:
840 frame.x = head_x; 783 frame.x = head_x;
841 frame.y = head_y + (head_h - frame.height) / 2; 784 frame.y = head_y + (head_h - frame.height) / 2;
842 frame.x_hidden = head_x + bevel_width - 785 frame.x_hidden = head_x + bevel_width - border_width - frame.width;
843 border_width - frame.width;
844 frame.y_hidden = frame.y; 786 frame.y_hidden = frame.y;
845 break; 787 break;
846 788
847 case BOTTOMLEFT: 789 case BOTTOMLEFT:
848 frame.x = head_x; 790 frame.x = head_x;
849 frame.y = head_y + head_h - frame.height - border_width*2; 791 frame.y = head_y + head_h - frame.height - border_width*2;
850 if (direction() == VERTICAL) { 792 frame.x_hidden = head_x;
851 frame.x_hidden = head_x + bevel_width - 793 frame.y_hidden = head_y + head_h - bevel_width - border_width;
852 border_width - frame.width; 794 break;
853 frame.y_hidden = frame.y; 795
854 } else { 796 case LEFTBOTTOM:
855 frame.x_hidden = head_x; 797 frame.x = head_x;
856 frame.y_hidden = head_y + head_h - 798 frame.y = head_y + head_h - frame.height - border_width*2;
857 bevel_width - border_width; 799 frame.x_hidden = head_x + bevel_width - border_width - frame.width;
858 } 800 frame.y_hidden = frame.y;
859 break; 801 break;
860 802
861 case TOPCENTER: 803 case TOPCENTER:
862 frame.x = head_x + ((head_w - frame.width) / 2); 804 frame.x = head_x + ((head_w - frame.width) / 2);
863 frame.y = head_y; 805 frame.y = head_y;
864 frame.x_hidden = frame.x; 806 frame.x_hidden = frame.x;
865 frame.y_hidden = head_y + bevel_width - 807 frame.y_hidden = head_y + bevel_width - border_width - frame.height;
866 border_width - frame.height;
867 break; 808 break;
868 809
869 case BOTTOMCENTER: 810 case BOTTOMCENTER:
870 frame.x = head_x + ((head_w - frame.width) / 2); 811 frame.x = head_x + ((head_w - frame.width) / 2);
871 frame.y = head_y + head_h - frame.height - border_width*2; 812 frame.y = head_y + head_h - frame.height - border_width*2;
872 frame.x_hidden = frame.x; 813 frame.x_hidden = frame.x;
873 frame.y_hidden = head_y + head_h - 814 frame.y_hidden = head_y + head_h - bevel_width - border_width;
874 bevel_width - border_width;
875 break; 815 break;
876 816
877 case TOPRIGHT: 817 case TOPRIGHT:
878 frame.x = head_x + head_w - frame.width - border_width*2; 818 frame.x = head_x + head_w - frame.width - border_width*2;
879 frame.y = head_y; 819 frame.y = head_y;
880 if (direction() == VERTICAL) { 820 frame.x_hidden = frame.x;
881 frame.x_hidden = head_x + head_w - 821 frame.y_hidden = head_y + bevel_width - border_width - frame.height;
882 bevel_width - border_width; 822 break;
883 frame.y_hidden = head_y; 823
884 } else { 824 case RIGHTTOP:
885 frame.x_hidden = frame.x; 825 frame.x = head_x + head_w - frame.width - border_width*2;
886 frame.y_hidden = head_y + bevel_width - 826 frame.y = head_y;
887 border_width - frame.height; 827 frame.x_hidden = head_x + head_w - bevel_width - border_width;
888 } 828 frame.y_hidden = head_y;
889 break; 829 break;
890 830
891 case RIGHTCENTER: 831 case RIGHTCENTER:
892 default:
893 frame.x = head_x + head_w - frame.width - border_width*2; 832 frame.x = head_x + head_w - frame.width - border_width*2;
894 frame.y = head_y + ((head_h - frame.height) / 2); 833 frame.y = head_y + ((head_h - frame.height) / 2);
895 frame.x_hidden = head_x + head_w - 834 frame.x_hidden = head_x + head_w - bevel_width - border_width;
896 bevel_width - border_width;
897 frame.y_hidden = frame.y; 835 frame.y_hidden = frame.y;
898 break; 836 break;
899 837
900 case BOTTOMRIGHT: 838 case BOTTOMRIGHT:
901 frame.x = head_x + head_w - frame.width - border_width*2; 839 frame.x = head_x + head_w - frame.width - border_width*2;
902 frame.y = head_y + head_h - frame.height - border_width*2; 840 frame.y = head_y + head_h - frame.height - border_width*2;
903 if (direction() == VERTICAL) { 841 frame.x_hidden = frame.x;
904 frame.x_hidden = head_x + head_w - 842 frame.y_hidden = head_y + head_h - bevel_width - border_width;
905 bevel_width - border_width; 843 break;
906 frame.y_hidden = frame.y; 844
907 } else { 845 case RIGHTBOTTOM:
908 frame.x_hidden = frame.x; 846 default:
909 frame.y_hidden = head_y + head_h - 847 frame.x = head_x + head_w - frame.width - border_width*2;
910 bevel_width - border_width; 848 frame.y = head_y + head_h - frame.height - border_width*2;
911 } 849 frame.x_hidden = head_x + head_w - bevel_width - border_width;
850 frame.y_hidden = frame.y;
912 break; 851 break;
913 } 852 }
914 853
@@ -1291,9 +1230,6 @@ void Slit::setupMenu() {
1291 1230
1292 m_slitmenu.insert(alpha_menuitem); 1231 m_slitmenu.insert(alpha_menuitem);
1293 1232
1294 m_slitmenu.insert(new SlitDirMenuItem(_FB_XTEXT(Slit, Direction, "Slit Direction", "Orientation of slit"),
1295 *this,
1296 save_and_reconfigure));
1297 m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu); 1233 m_slitmenu.insert(_FB_XTEXT(Slit, ClientsMenu, "Clients", "Slit client menu"), &m_clientlist_menu);
1298 m_slitmenu.updateMenu(); 1234 m_slitmenu.updateMenu();
1299 1235
@@ -1310,18 +1246,24 @@ void Slit::setupMenu() {
1310 1246
1311 // menu is 3 wide, 5 down 1247 // menu is 3 wide, 5 down
1312 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), Slit::TOPLEFT)); 1248 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopLeft, "Top Left", "Top Left"), Slit::TOPLEFT));
1249 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftTop, "Left Top", "Left Top"), Slit::LEFTTOP));
1313 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), Slit::LEFTCENTER)); 1250 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftCenter, "Left Center", "Left Center"), Slit::LEFTCENTER));
1251 place_menu.push_back(PlacementP(_FB_XTEXT(Align, LeftBottom, "Left Bottom", "Left Bottom"), Slit::LEFTBOTTOM));
1314 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), Slit::BOTTOMLEFT)); 1252 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomLeft, "Bottom Left", "Bottom Left"), Slit::BOTTOMLEFT));
1315 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), Slit::TOPCENTER)); 1253 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopCenter, "Top Center", "Top Center"), Slit::TOPCENTER));
1316 place_menu.push_back(PlacementP("", Slit::TOPLEFT)); 1254 place_menu.push_back(PlacementP("", Slit::TOPLEFT));
1255 place_menu.push_back(PlacementP("", Slit::TOPLEFT));
1256 place_menu.push_back(PlacementP("", Slit::TOPLEFT));
1317 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), Slit::BOTTOMCENTER)); 1257 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomCenter, "Bottom Center", "Bottom Center"), Slit::BOTTOMCENTER));
1318 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), Slit::TOPRIGHT)); 1258 place_menu.push_back(PlacementP(_FB_XTEXT(Align, TopRight, "Top Right", "Top Right"), Slit::TOPRIGHT));
1259 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightTop, "Right Top", "Right Top"), Slit::RIGHTTOP));
1319 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), Slit::RIGHTCENTER)); 1260 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightCenter, "Right Center", "Right Center"), Slit::RIGHTCENTER));
1261 place_menu.push_back(PlacementP(_FB_XTEXT(Align, RightBottom, "Right Bottom", "Right Bottom"), Slit::RIGHTBOTTOM));
1320 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Slit::BOTTOMRIGHT)); 1262 place_menu.push_back(PlacementP(_FB_XTEXT(Align, BottomRight, "Bottom Right", "Bottom Right"), Slit::BOTTOMRIGHT));
1321 1263
1322 1264
1323 // create items in sub menu 1265 // create items in sub menu
1324 for (size_t i=0; i<9; ++i) { 1266 for (size_t i=0; i<15; ++i) {
1325 const FbTk::FbString &str = place_menu.front().first; 1267 const FbTk::FbString &str = place_menu.front().first;
1326 Slit::Placement placement = place_menu.front().second; 1268 Slit::Placement placement = place_menu.front().second;
1327 1269