aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Kinnunen <fluxgen@fluxbox.org>2008-05-09 17:39:02 (GMT)
committerHenrik Kinnunen <fluxgen@fluxbox.org>2008-05-09 17:39:02 (GMT)
commitc31638038aabd93c74373c7ee00fbefbc68d28ae (patch)
treeda658ad65f64c24495cfdc169449250efb5caac0 /src
parent05fa2be09642ff135eb32a4528103adf89cd71e7 (diff)
downloadfluxbox-c31638038aabd93c74373c7ee00fbefbc68d28ae.zip
fluxbox-c31638038aabd93c74373c7ee00fbefbc68d28ae.tar.bz2
Fixed so tooltip window in the iconbar when the title changes.
Diffstat (limited to 'src')
-rw-r--r--src/IconButton.cc29
-rw-r--r--src/IconButton.hh5
-rw-r--r--src/OSDWindow.hh9
-rw-r--r--src/Screen.cc28
-rw-r--r--src/Screen.hh13
-rw-r--r--src/TooltipWindow.cc53
-rw-r--r--src/TooltipWindow.hh40
7 files changed, 114 insertions, 63 deletions
diff --git a/src/IconButton.cc b/src/IconButton.cc
index 6b8118e..0511a06 100644
--- a/src/IconButton.cc
+++ b/src/IconButton.cc
@@ -55,6 +55,7 @@ IconButton::IconButton(const FbTk::FbWindow &parent,
55 ExposureMask |EnterWindowMask | LeaveWindowMask | 55 ExposureMask |EnterWindowMask | LeaveWindowMask |
56 ButtonPressMask | ButtonReleaseMask), 56 ButtonPressMask | ButtonReleaseMask),
57 m_use_pixmap(true), 57 m_use_pixmap(true),
58 m_has_tooltip(false),
58 m_theme(win, focused_theme, unfocused_theme), 59 m_theme(win, focused_theme, unfocused_theme),
59 m_pm(win.screen().imageControl()) { 60 m_pm(win.screen().imageControl()) {
60 61
@@ -81,16 +82,12 @@ void IconButton::exposeEvent(XExposeEvent &event) {
81} 82}
82 83
83void IconButton::enterNotifyEvent(XCrossingEvent &ev) { 84void IconButton::enterNotifyEvent(XCrossingEvent &ev) {
84 85 m_has_tooltip = true;
85 int xoffset = 1; 86 showTooltip();
86 if (m_icon_pixmap.drawable() != 0)
87 xoffset = m_icon_window.x() + m_icon_window.width() + 1;
88
89 if (FbTk::TextButton::textExceeds(xoffset))
90 m_win.screen().showTooltip(m_win.title());
91} 87}
92 88
93void IconButton::leaveNotifyEvent(XCrossingEvent &ev) { 89void IconButton::leaveNotifyEvent(XCrossingEvent &ev) {
90 m_has_tooltip = false;
94 m_win.screen().hideTooltip(); 91 m_win.screen().hideTooltip();
95} 92}
96 93
@@ -113,6 +110,15 @@ void IconButton::resize(unsigned int width, unsigned int height) {
113 } 110 }
114} 111}
115 112
113void IconButton::showTooltip() {
114 int xoffset = 1;
115 if (m_icon_pixmap.drawable() != 0)
116 xoffset = m_icon_window.x() + m_icon_window.width() + 1;
117
118 if (FbTk::TextButton::textExceeds(xoffset))
119 m_win.screen().showTooltip(m_win.title());
120}
121
116void IconButton::clear() { 122void IconButton::clear() {
117 setupWindow(); 123 setupWindow();
118} 124}
@@ -230,6 +236,15 @@ void IconButton::update(FbTk::Subject *subj) {
230 } else { 236 } else {
231 m_icon_window.clear(); 237 m_icon_window.clear();
232 } 238 }
239 // if the title was changed AND the tooltip window is visible AND
240 // we have had an enter notify event ( without the leave notify )
241 // update the text inside it
242 if (subj == &m_win.titleSig() &&
243 m_has_tooltip &&
244 m_win.screen().tooltipWindow().isVisible()) {
245 m_win.screen().tooltipWindow().updateText(m_win.title());
246 }
247
233} 248}
234 249
235void IconButton::setupWindow() { 250void IconButton::setupWindow() {
diff --git a/src/IconButton.hh b/src/IconButton.hh
index bb41b8b..2a81c85 100644
--- a/src/IconButton.hh
+++ b/src/IconButton.hh
@@ -69,13 +69,16 @@ protected:
69 void drawText(int x, int y, FbTk::FbDrawable *drawable_override); 69 void drawText(int x, int y, FbTk::FbDrawable *drawable_override);
70private: 70private:
71 void setupWindow(); 71 void setupWindow();
72 void showTooltip();
72 73
73 Focusable &m_win; 74 Focusable &m_win;
74 FbTk::FbWindow m_icon_window; 75 FbTk::FbWindow m_icon_window;
75 FbTk::FbPixmap m_icon_pixmap; 76 FbTk::FbPixmap m_icon_pixmap;
76 FbTk::FbPixmap m_icon_mask; 77 FbTk::FbPixmap m_icon_mask;
77 bool m_use_pixmap; 78 bool m_use_pixmap;
78 79 /// whether or not this instance has the tooltip attention
80 /// i.e if it got enter notify
81 bool m_has_tooltip;
79 FocusableTheme<IconbarTheme> m_theme; 82 FocusableTheme<IconbarTheme> m_theme;
80 // cached pixmaps 83 // cached pixmaps
81 FbTk::CachedPixmap m_pm; 84 FbTk::CachedPixmap m_pm;
diff --git a/src/OSDWindow.hh b/src/OSDWindow.hh
index e11a531..4a070a2 100644
--- a/src/OSDWindow.hh
+++ b/src/OSDWindow.hh
@@ -46,8 +46,15 @@ public:
46 void hide(); 46 void hide();
47 47
48 bool isVisible() const { return m_visible; } 48 bool isVisible() const { return m_visible; }
49 49 BScreen &screen() const { return m_screen; }
50 FbTk::ThemeProxy<FbWinFrameTheme> &theme() { return m_theme; }
50protected: 51protected:
52 /// Force visible status, use with care.
53 void setVisible(bool visible) {
54 m_visible = visible;
55 }
56
57private:
51 void show(); 58 void show();
52 59
53 BScreen &m_screen; 60 BScreen &m_screen;
diff --git a/src/Screen.cc b/src/Screen.cc
index 48a5c10..1ae5fbc 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -342,9 +342,9 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
342 m_pressed_winbutton_theme(new WinButtonTheme(scrn, ".pressed", ".Pressed", *m_focused_windowtheme)), 342 m_pressed_winbutton_theme(new WinButtonTheme(scrn, ".pressed", ".Pressed", *m_focused_windowtheme)),
343 m_menutheme(new FbTk::MenuTheme(scrn)), 343 m_menutheme(new FbTk::MenuTheme(scrn)),
344 m_root_window(scrn), 344 m_root_window(scrn),
345 m_geom_window(m_root_window, *this, *m_focused_windowtheme), 345 m_geom_window(new OSDWindow(m_root_window, *this, *m_focused_windowtheme)),
346 m_pos_window(m_root_window, *this, *m_focused_windowtheme), 346 m_pos_window(new OSDWindow(m_root_window, *this, *m_focused_windowtheme)),
347 m_tooltip_window(m_root_window, *this, *m_focused_windowtheme), 347 m_tooltip_window(new TooltipWindow(m_root_window, *this, *m_focused_windowtheme)),
348 m_dummy_window(scrn, -1, -1, 1, 1, 0, true, false, CopyFromParent, 348 m_dummy_window(scrn, -1, -1, 1, 1, 0, true, false, CopyFromParent,
349 InputOnly), 349 InputOnly),
350 resource(rm, screenname, altscreenname), 350 resource(rm, screenname, altscreenname),
@@ -486,7 +486,7 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
486 486
487 renderGeomWindow(); 487 renderGeomWindow();
488 renderPosWindow(); 488 renderPosWindow();
489 m_tooltip_window.setDelay(*resource.tooltip_delay); 489 m_tooltip_window->setDelay(*resource.tooltip_delay);
490 490
491 // setup workspaces and workspace menu 491 // setup workspaces and workspace menu
492 int nr_ws = *resource.workspaces; 492 int nr_ws = *resource.workspaces;
@@ -1827,12 +1827,12 @@ void BScreen::showPosition(int x, int y) {
1827 1827
1828 char label[256]; 1828 char label[256];
1829 sprintf(label, "X:%5d x Y:%5d", x, y); 1829 sprintf(label, "X:%5d x Y:%5d", x, y);
1830 m_pos_window.showText(label); 1830 m_pos_window->showText(label);
1831} 1831}
1832 1832
1833 1833
1834void BScreen::hidePosition() { 1834void BScreen::hidePosition() {
1835 m_pos_window.hide(); 1835 m_pos_window->hide();
1836} 1836}
1837 1837
1838// can be negative when base_width/height > min_width/height 1838// can be negative when base_width/height > min_width/height
@@ -1848,23 +1848,23 @@ void BScreen::showGeometry(int gx, int gy) {
1848 "W: %4d x H: %4d", 1848 "W: %4d x H: %4d",
1849 "Format for width and height window, %4d for width, and %4d for height").c_str(), 1849 "Format for width and height window, %4d for width, and %4d for height").c_str(),
1850 gx, gy); 1850 gx, gy);
1851 m_geom_window.showText(label); 1851 m_geom_window->showText(label);
1852} 1852}
1853 1853
1854 1854
1855void BScreen::showTooltip(const std::string &text) { 1855void BScreen::showTooltip(const std::string &text) {
1856 if (*resource.tooltip_delay >= 0) 1856 if (*resource.tooltip_delay >= 0)
1857 m_tooltip_window.showText(text); 1857 m_tooltip_window->showText(text);
1858} 1858}
1859 1859
1860void BScreen::hideTooltip() { 1860void BScreen::hideTooltip() {
1861 if (*resource.tooltip_delay >= 0) 1861 if (*resource.tooltip_delay >= 0)
1862 m_tooltip_window.hide(); 1862 m_tooltip_window->hide();
1863} 1863}
1864 1864
1865 1865
1866void BScreen::hideGeometry() { 1866void BScreen::hideGeometry() {
1867 m_geom_window.hide(); 1867 m_geom_window->hide();
1868} 1868}
1869 1869
1870void BScreen::setLayer(FbTk::XLayerItem &item, int layernum) { 1870void BScreen::setLayer(FbTk::XLayerItem &item, int layernum) {
@@ -1912,14 +1912,14 @@ void BScreen::renderGeomWindow() {
1912 _FB_XTEXT(Screen, GeometrySpacing, 1912 _FB_XTEXT(Screen, GeometrySpacing,
1913 "W: %04d x H: %04d", "Representative maximum sized text for width and height dialog").c_str(), 1913 "W: %04d x H: %04d", "Representative maximum sized text for width and height dialog").c_str(),
1914 0, 0); 1914 0, 0);
1915 m_geom_window.resize(label); 1915 m_geom_window->resize(label);
1916 m_geom_window.reconfigTheme(); 1916 m_geom_window->reconfigTheme();
1917} 1917}
1918 1918
1919 1919
1920void BScreen::renderPosWindow() { 1920void BScreen::renderPosWindow() {
1921 m_pos_window.resize("0:00000 x 0:00000"); 1921 m_pos_window->resize("0:00000 x 0:00000");
1922 m_pos_window.reconfigTheme(); 1922 m_pos_window->reconfigTheme();
1923} 1923}
1924 1924
1925void BScreen::updateSize() { 1925void BScreen::updateSize() {
diff --git a/src/Screen.hh b/src/Screen.hh
index cf8bf1f..02fcc0d 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -64,6 +64,8 @@ class Toolbar;
64class HeadArea; 64class HeadArea;
65class FocusControl; 65class FocusControl;
66class ScreenPlacement; 66class ScreenPlacement;
67class TooltipWindow;
68class OSDWindow;
67 69
68namespace FbTk { 70namespace FbTk {
69class Menu; 71class Menu;
@@ -73,6 +75,7 @@ class FbWindow;
73class Subject; 75class Subject;
74} 76}
75 77
78
76/// Handles screen connection, screen clients and workspaces 79/// Handles screen connection, screen clients and workspaces
77/** 80/**
78 Create workspaces, handles switching between workspaces and windows 81 Create workspaces, handles switching between workspaces and windows
@@ -389,10 +392,14 @@ public:
389 /// show geomentry with "width x height"-text, not size of window 392 /// show geomentry with "width x height"-text, not size of window
390 void showGeometry(int width, int height); 393 void showGeometry(int width, int height);
391 void hideGeometry(); 394 void hideGeometry();
392 395
396 /// @param text the text to be displayed in the tooltip window
393 void showTooltip(const std::string &text); 397 void showTooltip(const std::string &text);
398 /// Hides the tooltip window
394 void hideTooltip(); 399 void hideTooltip();
395 400
401 TooltipWindow& tooltipWindow() { return *m_tooltip_window; }
402
396 void setLayer(FbTk::XLayerItem &item, int layernum); 403 void setLayer(FbTk::XLayerItem &item, int layernum);
397 // remove? no, items are never removed from their layer until they die 404 // remove? no, items are never removed from their layer until they die
398 405
@@ -538,8 +545,8 @@ private:
538 std::auto_ptr<RootTheme> m_root_theme; 545 std::auto_ptr<RootTheme> m_root_theme;
539 546
540 FbRootWindow m_root_window; 547 FbRootWindow m_root_window;
541 OSDWindow m_geom_window, m_pos_window; 548 std::auto_ptr<OSDWindow> m_geom_window, m_pos_window;
542 TooltipWindow m_tooltip_window; 549 std::auto_ptr<TooltipWindow> m_tooltip_window;
543 FbTk::FbWindow m_dummy_window; 550 FbTk::FbWindow m_dummy_window;
544 551
545 struct ScreenResource { 552 struct ScreenResource {
diff --git a/src/TooltipWindow.cc b/src/TooltipWindow.cc
index 42926d8..284f232 100644
--- a/src/TooltipWindow.cc
+++ b/src/TooltipWindow.cc
@@ -28,33 +28,35 @@
28TooltipWindow::TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen, 28TooltipWindow::TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen,
29 FbTk::ThemeProxy<FbWinFrameTheme> &theme): 29 FbTk::ThemeProxy<FbWinFrameTheme> &theme):
30 OSDWindow(parent, screen, theme), 30 OSDWindow(parent, screen, theme),
31 delay(-1) { 31 m_delay(-1) {
32 32
33 FbTk::RefCount<FbTk::Command<void> > raisecmd(new FbTk::SimpleCommand<TooltipWindow>(*this, &TooltipWindow::raiseTooltip)); 33 FbTk::RefCount<FbTk::Command<void> >
34 timer.setCommand(raisecmd); 34 raisecmd(new FbTk::SimpleCommand<TooltipWindow>(*this,
35 timer.fireOnce(true); 35 &TooltipWindow::raiseTooltip));
36 m_timer.setCommand(raisecmd);
37 m_timer.fireOnce(true);
36 38
37} 39}
38 40
39void TooltipWindow::showText(const std::string &text) { 41void TooltipWindow::showText(const std::string &text) {
40 42
41 lastText = text.c_str(); 43 m_lastText = text;
42 if (delay == 0) 44 if (m_delay == 0)
43 raiseTooltip(); 45 raiseTooltip();
44 else 46 else
45 timer.start(); 47 m_timer.start();
46 48
47} 49}
48 50
49void TooltipWindow::raiseTooltip() { 51void TooltipWindow::raiseTooltip() {
50 52
51 if (lastText.size() == 0) 53 if (m_lastText.empty())
52 return; 54 return;
53 55
54 resize(lastText); 56 resize(m_lastText);
55 reconfigTheme(); 57 reconfigTheme();
56 int h = m_theme->font().height() + m_theme->bevelWidth() * 2; 58 int h = theme()->font().height() + theme()->bevelWidth() * 2;
57 int w = m_theme->font().textWidth(lastText, lastText.size()) + m_theme->bevelWidth() * 2; 59 int w = theme()->font().textWidth(m_lastText, m_lastText.size()) + theme()->bevelWidth() * 2;
58 60
59 Window root_ret; // not used 61 Window root_ret; // not used
60 Window window_ret; // not used 62 Window window_ret; // not used
@@ -62,13 +64,13 @@ void TooltipWindow::raiseTooltip() {
62 int wx, wy; // not used 64 int wx, wy; // not used
63 unsigned int mask; // not used 65 unsigned int mask; // not used
64 66
65 XQueryPointer(display(), m_screen.rootWindow().window(), 67 XQueryPointer(display(), screen().rootWindow().window(),
66 &root_ret, &window_ret, &rx, &ry, &wx, &wy, &mask); 68 &root_ret, &window_ret, &rx, &ry, &wx, &wy, &mask);
67 69
68 int head = m_screen.getHead(rx, ry); 70 int head = screen().getHead(rx, ry);
69 int head_top = m_screen.getHeadY(head); 71 int head_top = screen().getHeadY(head);
70 int head_left = m_screen.getHeadX(head); 72 int head_left = screen().getHeadX(head);
71 int head_right = head_left + m_screen.getHeadWidth(head); 73 int head_right = head_left + screen().getHeadWidth(head);
72 74
73 // center the mouse horizontally 75 // center the mouse horizontally
74 rx -= w/2; 76 rx -= w/2;
@@ -88,22 +90,27 @@ void TooltipWindow::raiseTooltip() {
88 90
89 show(); 91 show();
90 clear(); 92 clear();
91 m_theme->font().drawText(*this, m_screen.screenNumber(), 93 theme()->font().drawText(*this, screen().screenNumber(),
92 m_theme->iconbarTheme().text().textGC(), lastText, 94 theme()->iconbarTheme().text().textGC(),
93 lastText.size(), m_theme->bevelWidth(), 95 m_lastText, m_lastText.size(),
94 m_theme->bevelWidth() + m_theme->font().ascent()); 96 theme()->bevelWidth(),
97 theme()->bevelWidth() + theme()->font().ascent());
95} 98}
96 99
100void TooltipWindow::updateText(const std::string &text) {
101 m_lastText = text;
102 raiseTooltip();
103}
97 104
98void TooltipWindow::show() { 105void TooltipWindow::show() {
99 if (m_visible) 106 if (isVisible())
100 return; 107 return;
101 m_visible = true; 108 setVisible(true);
102 raise(); 109 raise();
103 FbTk::FbWindow::show(); 110 FbTk::FbWindow::show();
104} 111}
105 112
106void TooltipWindow::hide() { 113void TooltipWindow::hide() {
107 timer.stop(); 114 m_timer.stop();
108 OSDWindow::hide(); 115 OSDWindow::hide();
109} 116}
diff --git a/src/TooltipWindow.hh b/src/TooltipWindow.hh
index 03abc1d..401e442 100644
--- a/src/TooltipWindow.hh
+++ b/src/TooltipWindow.hh
@@ -17,9 +17,10 @@
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.#ifndef TOOLTIPWINDOW_HH_ 20// DEALINGS IN THE SOFTWARE.
21#ifndef TOOLTIPWINDOW_HH_ 21
22#define TOOLTIPWINDOW_HH_ 22#ifndef TOOLTIPWINDOW_HH
23#define TOOLTIPWINDOW_HH
23 24
24#include "OSDWindow.hh" 25#include "OSDWindow.hh"
25#include "FbTk/Command.hh" 26#include "FbTk/Command.hh"
@@ -27,27 +28,38 @@
27#include "FbTk/Timer.hh" 28#include "FbTk/Timer.hh"
28#include "FbTk/SimpleCommand.hh" 29#include "FbTk/SimpleCommand.hh"
29 30
30 31/**
32 * Displays a tooltip window
33 */
31class TooltipWindow : public OSDWindow { 34class TooltipWindow : public OSDWindow {
32public: 35public:
33 TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen, 36 TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen,
34 FbTk::ThemeProxy<FbWinFrameTheme> &theme); 37 FbTk::ThemeProxy<FbWinFrameTheme> &theme);
35 38 /**
39 * Sets the text in the window and starts the display timer.
40 * @param text the text to show in the window.
41 */
36 void showText(const std::string &text); 42 void showText(const std::string &text);
37 void setDelay(int iDelay) { 43 /// updates the text directly without any delay
38 delay = iDelay; 44 void updateText(const std::string &text);
39 timer.setTimeout(delay); 45
46 /// Sets the delay before the window pops up
47 void setDelay(int delay) {
48 m_delay = delay;
49 m_timer.setTimeout(delay);
40 } 50 }
41 void hide() ; 51
52 void hide();
53
42 54
43private: 55private:
44 void raiseTooltip(); 56 void raiseTooltip();
45 void show(); 57 void show();
46 int delay; 58 int m_delay; ///< delay time for the timer
47 std::string lastText; 59 std::string m_lastText; ///< last text to be displayed
48 FbTk::Timer timer; 60 FbTk::Timer m_timer; ///< delay timer before the tooltip will show
49}; 61};
50 62
51 63
52 64
53#endif /*TOOLTIPWINDOW_HH_*/ 65#endif // TOOLTIPWINDOW_HH_