summaryrefslogtreecommitdiff
path: root/src/TooltipWindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/TooltipWindow.cc')
-rw-r--r--src/TooltipWindow.cc116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/TooltipWindow.cc b/src/TooltipWindow.cc
new file mode 100644
index 0000000..284f232
--- /dev/null
+++ b/src/TooltipWindow.cc
@@ -0,0 +1,116 @@
1// TooltipWindow.hh
2// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
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
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22
23#include "TooltipWindow.hh"
24#include "Screen.hh"
25#include "FbWinFrameTheme.hh"
26
27
28TooltipWindow::TooltipWindow(const FbTk::FbWindow &parent, BScreen &screen,
29 FbTk::ThemeProxy<FbWinFrameTheme> &theme):
30 OSDWindow(parent, screen, theme),
31 m_delay(-1) {
32
33 FbTk::RefCount<FbTk::Command<void> >
34 raisecmd(new FbTk::SimpleCommand<TooltipWindow>(*this,
35 &TooltipWindow::raiseTooltip));
36 m_timer.setCommand(raisecmd);
37 m_timer.fireOnce(true);
38
39}
40
41void TooltipWindow::showText(const std::string &text) {
42
43 m_lastText = text;
44 if (m_delay == 0)
45 raiseTooltip();
46 else
47 m_timer.start();
48
49}
50
51void TooltipWindow::raiseTooltip() {
52
53 if (m_lastText.empty())
54 return;
55
56 resize(m_lastText);
57 reconfigTheme();
58 int h = theme()->font().height() + theme()->bevelWidth() * 2;
59 int w = theme()->font().textWidth(m_lastText, m_lastText.size()) + theme()->bevelWidth() * 2;
60
61 Window root_ret; // not used
62 Window window_ret; // not used
63 int rx = 0, ry = 0;
64 int wx, wy; // not used
65 unsigned int mask; // not used
66
67 XQueryPointer(display(), screen().rootWindow().window(),
68 &root_ret, &window_ret, &rx, &ry, &wx, &wy, &mask);
69
70 int head = screen().getHead(rx, ry);
71 int head_top = screen().getHeadY(head);
72 int head_left = screen().getHeadX(head);
73 int head_right = head_left + screen().getHeadWidth(head);
74
75 // center the mouse horizontally
76 rx -= w/2;
77 int yoffset = 10;
78 if (ry - yoffset - h >= head_top)
79 ry -= yoffset + h;
80 else
81 ry += yoffset;
82
83 // check that we are not out of screen
84 if (rx + w > head_right)
85 rx = head_right - w;
86 if (rx < head_left)
87 rx = head_left;
88
89 moveResize(rx,ry,w, h);
90
91 show();
92 clear();
93 theme()->font().drawText(*this, screen().screenNumber(),
94 theme()->iconbarTheme().text().textGC(),
95 m_lastText, m_lastText.size(),
96 theme()->bevelWidth(),
97 theme()->bevelWidth() + theme()->font().ascent());
98}
99
100void TooltipWindow::updateText(const std::string &text) {
101 m_lastText = text;
102 raiseTooltip();
103}
104
105void TooltipWindow::show() {
106 if (isVisible())
107 return;
108 setVisible(true);
109 raise();
110 FbTk::FbWindow::show();
111}
112
113void TooltipWindow::hide() {
114 m_timer.stop();
115 OSDWindow::hide();
116}