aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbCommands.cc40
-rw-r--r--src/IconbarTool.cc6
-rw-r--r--src/ScreenPlacement.cc49
-rw-r--r--src/ScreenPlacement.hh7
-rw-r--r--src/Slit.cc18
-rw-r--r--src/ToolFactory.cc25
-rw-r--r--src/Toolbar.cc20
-rw-r--r--src/Window.cc26
8 files changed, 88 insertions, 103 deletions
diff --git a/src/FbCommands.cc b/src/FbCommands.cc
index 4dffd8d..be52e47 100644
--- a/src/FbCommands.cc
+++ b/src/FbCommands.cc
@@ -22,6 +22,7 @@
22#include "FbCommands.hh" 22#include "FbCommands.hh"
23#include "fluxbox.hh" 23#include "fluxbox.hh"
24#include "Screen.hh" 24#include "Screen.hh"
25#include "ScreenPlacement.hh"
25#include "CommandDialog.hh" 26#include "CommandDialog.hh"
26#include "FocusControl.hh" 27#include "FocusControl.hh"
27#include "Workspace.hh" 28#include "Workspace.hh"
@@ -71,7 +72,7 @@ using std::ios;
71 72
72namespace { 73namespace {
73 74
74void showMenu(const BScreen &screen, FbTk::Menu &menu) { 75void showMenu(BScreen &screen, FbTk::Menu &menu) {
75 76
76 // check if menu has changed 77 // check if menu has changed
77 if (typeid(menu) == typeid(FbMenu)) { 78 if (typeid(menu) == typeid(FbMenu)) {
@@ -82,36 +83,19 @@ void showMenu(const BScreen &screen, FbTk::Menu &menu) {
82 83
83 FbMenu::setWindow(FocusControl::focusedFbWindow()); 84 FbMenu::setWindow(FocusControl::focusedFbWindow());
84 85
85 Window root_ret; // not used 86 Window ignored_w;
86 Window window_ret; // not used 87 int ignored_i;
88 unsigned int ignored_ui;
87 89
88 int rx = 0, ry = 0; 90 int x = 0;
89 int wx, wy; // not used 91 int y = 0;
90 unsigned int mask; // not used
91 92
92 XQueryPointer(menu.fbwindow().display(), 93 XQueryPointer(menu.fbwindow().display(),
93 screen.rootWindow().window(), &root_ret, &window_ret, 94 screen.rootWindow().window(), &ignored_w, &ignored_w,
94 &rx, &ry, &wx, &wy, &mask); 95 &x, &y, &ignored_i, &ignored_i, &ignored_ui);
95 96
96 int borderw = menu.fbwindow().borderWidth(); 97 screen.placementStrategy()
97 int head = screen.getHead(rx, ry); 98 .placeAndShowMenu(menu, x, y, false);
98
99 menu.updateMenu();
100 pair<int, int> m =
101 screen.clampToHead(head,
102 rx - menu.width() / 2,
103 ry - menu.titleWindow().height() / 2,
104 menu.width() + 2*borderw,
105 menu.height() + 2*borderw);
106
107 menu.move(m.first, m.second);
108 menu.setScreen(screen.getHeadX(head),
109 screen.getHeadY(head),
110 screen.getHeadWidth(head),
111 screen.getHeadHeight(head));
112
113 menu.show();
114 menu.grabInputFocus();
115} 99}
116 100
117} 101}
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc
index 62eae0d..932121f 100644
--- a/src/IconbarTool.cc
+++ b/src/IconbarTool.cc
@@ -212,10 +212,8 @@ public:
212 explicit ShowMenu(FluxboxWindow &win):m_win(win) { } 212 explicit ShowMenu(FluxboxWindow &win):m_win(win) { }
213 void execute() { 213 void execute() {
214 // get last button pos 214 // get last button pos
215 const XEvent &event = Fluxbox::instance()->lastEvent(); 215 const XEvent &e = Fluxbox::instance()->lastEvent();
216 int x = event.xbutton.x_root - (m_win.menu().width() / 2); 216 m_win.popupMenu(e.xbutton.x_root, e.xbutton.y_root);
217 int y = event.xbutton.y_root - (m_win.menu().height() / 2);
218 m_win.popupMenu(x, y);
219 } 217 }
220private: 218private:
221 FluxboxWindow &m_win; 219 FluxboxWindow &m_win;
diff --git a/src/ScreenPlacement.cc b/src/ScreenPlacement.cc
index 3e0c377..46ff718 100644
--- a/src/ScreenPlacement.cc
+++ b/src/ScreenPlacement.cc
@@ -30,6 +30,8 @@
30#include "Screen.hh" 30#include "Screen.hh"
31#include "Window.hh" 31#include "Window.hh"
32 32
33#include "FbTk/Menu.hh"
34
33#include <iostream> 35#include <iostream>
34#include <exception> 36#include <exception>
35#ifdef HAVE_CSTRING 37#ifdef HAVE_CSTRING
@@ -51,7 +53,8 @@ ScreenPlacement::ScreenPlacement(BScreen &screen):
51 screen.name()+".windowPlacement", 53 screen.name()+".windowPlacement",
52 screen.altName()+".WindowPlacement"), 54 screen.altName()+".WindowPlacement"),
53 m_old_policy(ROWSMARTPLACEMENT), 55 m_old_policy(ROWSMARTPLACEMENT),
54 m_strategy(0) 56 m_strategy(0),
57 m_screen(screen)
55{ 58{
56} 59}
57 60
@@ -128,7 +131,51 @@ bool ScreenPlacement::placeWindow(const FluxboxWindow &win, int head,
128 return true; 131 return true;
129} 132}
130 133
134bool ScreenPlacement::placeAndShowMenu(FbTk::Menu& menu, int x, int y, bool respect_struts) {
135
136 int head = m_screen.getHead(x, y);
137
138 menu.setScreen(m_screen.getHeadX(head),
139 m_screen.getHeadY(head),
140 m_screen.getHeadWidth(head),
141 m_screen.getHeadHeight(head));
142
143 menu.updateMenu(); // recalculate the size
144
145 x = x - (menu.width() / 2);
146 if (menu.isTitleVisible())
147 y = y - (menu.titleWindow().height() / 2);
148
149 // adjust (x, y) to fit on the screen
150 if (!respect_struts) {
151
152 int bw = 2 * menu.fbwindow().borderWidth();
153 std::pair<int, int> pos = m_screen.clampToHead(head, x, y, menu.width() + bw, menu.height() + bw);
154 x = pos.first;
155 y = pos.second;
131 156
157 } else { // do not cover toolbar if no title
158
159 int top = static_cast<signed>(m_screen.maxTop(head));
160 int bottom = static_cast<signed>(m_screen.maxBottom(head));
161 int left = static_cast<signed>(m_screen.maxLeft(head));
162 int right = static_cast<signed>(m_screen.maxRight(head));
163
164 if (y < top)
165 y = top;
166 else if (y + static_cast<signed>(menu.height()) >= bottom)
167 y = bottom - menu.height() - 1 - menu.fbwindow().borderWidth();
168
169 if (x < left)
170 x = left;
171 else if (x + static_cast<signed>(menu.width()) >= right)
172 x = right - static_cast<int>(menu.width()) - 1;
173 }
174
175 menu.move(x, y);
176 menu.show();
177 menu.grabInputFocus();
178}
132 179
133////////////////////// Placement Resources 180////////////////////// Placement Resources
134namespace FbTk { 181namespace FbTk {
diff --git a/src/ScreenPlacement.hh b/src/ScreenPlacement.hh
index b60726f..7093c9b 100644
--- a/src/ScreenPlacement.hh
+++ b/src/ScreenPlacement.hh
@@ -27,6 +27,9 @@
27 27
28#include <memory> 28#include <memory>
29 29
30namespace FbTk {
31 class Menu;
32}
30class BScreen; 33class BScreen;
31 34
32/** 35/**
@@ -65,6 +68,9 @@ public:
65 bool placeWindow(const FluxboxWindow &window, int head, 68 bool placeWindow(const FluxboxWindow &window, int head,
66 int &place_x, int &place_y); 69 int &place_x, int &place_y);
67 70
71 // places and show 'menu' at 'x','y'
72 bool placeAndShowMenu(FbTk::Menu& menu, int x, int y, bool respect_struts);
73
68 RowDirection rowDirection() const { return *m_row_direction; } 74 RowDirection rowDirection() const { return *m_row_direction; }
69 ColumnDirection colDirection() const { return *m_col_direction; } 75 ColumnDirection colDirection() const { return *m_col_direction; }
70 76
@@ -75,6 +81,7 @@ private:
75 PlacementPolicy m_old_policy; ///< holds old policy, used to determine if resources has changed 81 PlacementPolicy m_old_policy; ///< holds old policy, used to determine if resources has changed
76 std::auto_ptr<PlacementStrategy> m_strategy; ///< main strategy 82 std::auto_ptr<PlacementStrategy> m_strategy; ///< main strategy
77 std::auto_ptr<PlacementStrategy> m_fallback_strategy; ///< a fallback strategy if the main strategy fails 83 std::auto_ptr<PlacementStrategy> m_fallback_strategy; ///< a fallback strategy if the main strategy fails
84 BScreen& m_screen;
78}; 85};
79 86
80#endif // SCREENPLACEMENT_HH 87#endif // SCREENPLACEMENT_HH
diff --git a/src/Slit.cc b/src/Slit.cc
index aa62997..8ad83dd 100644
--- a/src/Slit.cc
+++ b/src/Slit.cc
@@ -34,6 +34,7 @@
34#endif // HAVE_CONFIG_H 34#endif // HAVE_CONFIG_H
35 35
36#include "Screen.hh" 36#include "Screen.hh"
37#include "ScreenPlacement.hh"
37#include "FbTk/ImageControl.hh" 38#include "FbTk/ImageControl.hh"
38#include "FbTk/RefCount.hh" 39#include "FbTk/RefCount.hh"
39#include "FbTk/EventManager.hh" 40#include "FbTk/EventManager.hh"
@@ -952,21 +953,8 @@ void Slit::buttonPressEvent(XButtonEvent &be) {
952 953
953 if (be.button == Button3) { 954 if (be.button == Button3) {
954 if (! m_slitmenu.isVisible()) { 955 if (! m_slitmenu.isVisible()) {
955 int head = screen().getHead(be.x_root, be.y_root); 956 screen().placementStrategy()
956 int borderw = m_slitmenu.fbwindow().borderWidth(); 957 .placeAndShowMenu(m_slitmenu, be.x_root, be.y_root, false);
957 pair<int, int> m = screen().clampToHead(head,
958 be.x_root - (m_slitmenu.width() / 2),
959 be.y_root - (m_slitmenu.titleWindow().height() / 2),
960 m_slitmenu.width() + 2*borderw,
961 m_slitmenu.height() + 2*borderw);
962
963 m_slitmenu.setScreen(screen().getHeadX(head),
964 screen().getHeadY(head),
965 screen().getHeadWidth(head),
966 screen().getHeadHeight(head));
967 m_slitmenu.move(m.first, m.second);
968 m_slitmenu.show();
969 m_slitmenu.grabInputFocus();
970 } else 958 } else
971 m_slitmenu.hide(); 959 m_slitmenu.hide();
972 } 960 }
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index 84184eb..b998a88 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -35,32 +35,21 @@
35 35
36#include "FbTk/CommandParser.hh" 36#include "FbTk/CommandParser.hh"
37#include "Screen.hh" 37#include "Screen.hh"
38#include "ScreenPlacement.hh"
38#include "Toolbar.hh" 39#include "Toolbar.hh"
39#include "fluxbox.hh" 40#include "fluxbox.hh"
40 41
41#include <utility>
42
43namespace { 42namespace {
44class ShowMenuAboveToolbar: public FbTk::Command<void> { 43class ShowMenuAboveToolbar: public FbTk::Command<void> {
45public: 44public:
46 explicit ShowMenuAboveToolbar(Toolbar &tbar):m_tbar(tbar) { } 45 explicit ShowMenuAboveToolbar(Toolbar &tbar):m_tbar(tbar) { }
47 void execute() { 46 void execute() {
48 // get last button pos 47
49 const XEvent &event = Fluxbox::instance()->lastEvent(); 48 const XEvent& e= Fluxbox::instance()->lastEvent();
50 int head = m_tbar.screen().getHead(event.xbutton.x_root, event.xbutton.y_root); 49
51 std::pair<int, int> m = 50 m_tbar.screen()
52 m_tbar.screen().clampToHead( head, 51 .placementStrategy()
53 event.xbutton.x_root - (m_tbar.menu().width() / 2), 52 .placeAndShowMenu(m_tbar.menu(), e.xbutton.x_root, e.xbutton.y_root, false);
54 event.xbutton.y_root - (m_tbar.menu().height() / 2),
55 m_tbar.menu().width(),
56 m_tbar.menu().height());
57 m_tbar.menu().setScreen(m_tbar.screen().getHeadX(head),
58 m_tbar.screen().getHeadY(head),
59 m_tbar.screen().getHeadWidth(head),
60 m_tbar.screen().getHeadHeight(head));
61 m_tbar.menu().move(m.first, m.second);
62 m_tbar.menu().show();
63 m_tbar.menu().grabInputFocus();
64 } 53 }
65private: 54private:
66 Toolbar &m_tbar; 55 Toolbar &m_tbar;
diff --git a/src/Toolbar.cc b/src/Toolbar.cc
index 896268f..cb1a956 100644
--- a/src/Toolbar.cc
+++ b/src/Toolbar.cc
@@ -33,6 +33,7 @@
33#include "fluxbox.hh" 33#include "fluxbox.hh"
34#include "Keys.hh" 34#include "Keys.hh"
35#include "Screen.hh" 35#include "Screen.hh"
36#include "ScreenPlacement.hh"
36#include "WindowCmd.hh" 37#include "WindowCmd.hh"
37 38
38#include "Strut.hh" 39#include "Strut.hh"
@@ -520,22 +521,9 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) {
520 if (be.button != 3) 521 if (be.button != 3)
521 return; 522 return;
522 523
523 int head = screen().getHead(be.x_root, be.y_root); 524 screen()
524 int borderw = menu().fbwindow().borderWidth(); 525 .placementStrategy()
525 pair<int, int> m = screen().clampToHead(head, 526 .placeAndShowMenu(menu(), be.x_root, be.y_root, false);
526 be.x_root - (menu().width() / 2),
527 be.y_root - (menu().titleWindow().height() / 2),
528 menu().width() + 2*borderw,
529 menu().height() + 2*borderw);
530
531 menu().setScreen(screen().getHeadX(head),
532 screen().getHeadY(head),
533 screen().getHeadWidth(head),
534 screen().getHeadHeight(head));
535 menu().move(m.first, m.second);
536 menu().show();
537 menu().grabInputFocus();
538
539} 527}
540 528
541void Toolbar::enterNotifyEvent(XCrossingEvent &ce) { 529void Toolbar::enterNotifyEvent(XCrossingEvent &ce) {
diff --git a/src/Window.cc b/src/Window.cc
index c87180d..51a66df 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -1880,30 +1880,14 @@ bool FluxboxWindow::getState() {
1880} 1880}
1881 1881
1882/** 1882/**
1883 Show the window menu at pos mx, my 1883 Show the window menu at pos x, y
1884*/ 1884*/
1885void FluxboxWindow::showMenu(int menu_x, int menu_y) { 1885void FluxboxWindow::showMenu(int x, int y) {
1886 menu().reloadHelper()->checkReload();
1887
1888 int head = screen().getHead(menu_x, menu_y);
1889
1890 menu().updateMenu(); // recalculate the menu size
1891
1892 // move menu directly under titlebar but not off the screen
1893 if (menu_y < static_cast<signed>(screen().maxTop(head)))
1894 menu_y = screen().maxTop(head);
1895 else if (menu_y + menu().height() >= screen().maxBottom(head))
1896 menu_y = screen().maxBottom(head) - menu().height() - 1 - menu().fbwindow().borderWidth();
1897
1898 if (menu_x < static_cast<signed>(screen().maxLeft(head)))
1899 menu_x = screen().maxLeft(head);
1900 else if (menu_x + static_cast<signed>(menu().width()) >= static_cast<signed>(screen().maxRight(head)))
1901 menu_x = screen().maxRight(head) - menu().width() - 1;
1902 1886
1887 menu().reloadHelper()->checkReload();
1903 FbMenu::setWindow(this); 1888 FbMenu::setWindow(this);
1904 menu().move(menu_x, menu_y); 1889 screen().placementStrategy()
1905 menu().show(); 1890 .placeAndShowMenu(menu(), x, y, true);
1906 menu().grabInputFocus();
1907} 1891}
1908 1892
1909void FluxboxWindow::popupMenu(int x, int y) { 1893void FluxboxWindow::popupMenu(int x, int y) {