diff options
author | fluxgen <fluxgen> | 2003-08-26 23:48:19 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-08-26 23:48:19 (GMT) |
commit | fe6b6f91723beaf0f7194f01884efd57ec2d34eb (patch) | |
tree | 49aeed26141e5509a7260d818f029f32f02ab3e1 | |
parent | 9d3b8d55ff550e4bf62275b6193ae6feb7d60056 (diff) | |
download | fluxbox-fe6b6f91723beaf0f7194f01884efd57ec2d34eb.zip fluxbox-fe6b6f91723beaf0f7194f01884efd57ec2d34eb.tar.bz2 |
workspace name setting tool
-rw-r--r-- | src/SetWorkspaceName.cc | 142 | ||||
-rw-r--r-- | src/SetWorkspaceName.hh | 56 |
2 files changed, 198 insertions, 0 deletions
diff --git a/src/SetWorkspaceName.cc b/src/SetWorkspaceName.cc new file mode 100644 index 0000000..1127c3b --- /dev/null +++ b/src/SetWorkspaceName.cc | |||
@@ -0,0 +1,142 @@ | |||
1 | // SetWorkspaceName.cc for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) | ||
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 | // $Id: SetWorkspaceName.cc,v 1.1 2003/08/26 23:48:19 fluxgen Exp $ | ||
23 | |||
24 | #include "SetWorkspaceName.hh" | ||
25 | |||
26 | #include "Screen.hh" | ||
27 | #include "Workspace.hh" | ||
28 | #include "WinClient.hh" | ||
29 | #include "FbWinFrameTheme.hh" | ||
30 | |||
31 | #include "FbTk/EventManager.hh" | ||
32 | #include "FbTk/App.hh" | ||
33 | |||
34 | #include <X11/keysym.h> | ||
35 | #include <X11/Xutil.h> | ||
36 | |||
37 | #include <iostream> | ||
38 | using namespace std; | ||
39 | |||
40 | SetWorkspaceName::SetWorkspaceName(BScreen &screen): | ||
41 | FbWindow(screen.rootWindow().screenNumber(), | ||
42 | 0, 0, 1, 1, 0), | ||
43 | m_textbox(*this, m_font, screen.currentWorkspace()->name()), | ||
44 | m_label(*this, m_font, "Set workspace name:"), | ||
45 | m_font("fixed"), | ||
46 | m_gc(XCreateGC(FbTk::App::instance()->display(), m_textbox.window(), | ||
47 | 0, 0)), | ||
48 | m_screen(screen), | ||
49 | m_move_x(0), | ||
50 | m_move_y(0) { | ||
51 | |||
52 | |||
53 | m_label.setGC(screen.winFrameTheme().labelTextFocusGC()); | ||
54 | m_label.setBackgroundColor(screen.winFrameTheme().labelFocusTexture().color()); | ||
55 | m_label.moveResize(0, 0, | ||
56 | 200, m_font.height() + 2); | ||
57 | m_label.setEventMask(m_label.eventMask() | ButtonPressMask | ButtonMotionMask); // we listen to motion notify too | ||
58 | m_label.show(); | ||
59 | |||
60 | m_textbox.setBackgroundColor(FbTk::Color("white", m_textbox.screenNumber())); | ||
61 | XGCValues gc_val; | ||
62 | FbTk::Color black("black", m_textbox.screenNumber()); | ||
63 | gc_val.foreground = black.pixel(); | ||
64 | XChangeGC(FbTk::App::instance()->display(), m_gc, | ||
65 | GCForeground, &gc_val); | ||
66 | m_textbox.setGC(m_gc); | ||
67 | m_textbox.moveResize(0, m_label.height(), | ||
68 | 200, m_font.height() + 2); | ||
69 | m_textbox.show(); | ||
70 | |||
71 | resize(200, m_textbox.height() + m_label.height()); | ||
72 | |||
73 | |||
74 | // move to center of the screen | ||
75 | move((screen.width() - width())/2, (screen.height() - height())/2); | ||
76 | |||
77 | // we need ConfigureNotify from children | ||
78 | FbTk::EventManager::instance()->addParent(*this, *this); | ||
79 | } | ||
80 | |||
81 | SetWorkspaceName::~SetWorkspaceName() { | ||
82 | FbTk::EventManager::instance()->remove(*this); | ||
83 | if (m_gc) | ||
84 | XFreeGC(FbTk::App::instance()->display(), m_gc); | ||
85 | |||
86 | hide(); | ||
87 | } | ||
88 | |||
89 | void SetWorkspaceName::show() { | ||
90 | FbTk::FbWindow::show(); | ||
91 | m_textbox.setInputFocus(); | ||
92 | m_textbox.setText(m_screen.currentWorkspace()->name()); | ||
93 | m_textbox.clear(); | ||
94 | m_label.clear(); | ||
95 | } | ||
96 | |||
97 | void SetWorkspaceName::hide() { | ||
98 | FbTk::FbWindow::hide(); | ||
99 | |||
100 | // return focus to fluxbox window | ||
101 | if (Fluxbox::instance()->getFocusedWindow() && | ||
102 | Fluxbox::instance()->getFocusedWindow()->fbwindow()) | ||
103 | Fluxbox::instance()->getFocusedWindow()->fbwindow()->setInputFocus(); | ||
104 | |||
105 | } | ||
106 | |||
107 | void SetWorkspaceName::buttonPressEvent(XButtonEvent &event) { | ||
108 | m_textbox.setInputFocus(); | ||
109 | m_move_x = event.x_root - x(); | ||
110 | m_move_y = event.y_root - y(); | ||
111 | } | ||
112 | |||
113 | void SetWorkspaceName::handleEvent(XEvent &event) { | ||
114 | if (event.type == ConfigureNotify && event.xconfigure.window != window()) { | ||
115 | moveResize(event.xconfigure.x, event.xconfigure.y, | ||
116 | event.xconfigure.width, event.xconfigure.height); | ||
117 | } else if (event.type == DestroyNotify) | ||
118 | delete this; | ||
119 | } | ||
120 | |||
121 | void SetWorkspaceName::motionNotifyEvent(XMotionEvent &event) { | ||
122 | int new_x = event.x_root - m_move_x; | ||
123 | int new_y = event.y_root - m_move_y; | ||
124 | move(new_x, new_y); | ||
125 | } | ||
126 | |||
127 | void SetWorkspaceName::keyPressEvent(XKeyEvent &event) { | ||
128 | if (event.state) | ||
129 | return; | ||
130 | |||
131 | KeySym ks; | ||
132 | char keychar[1]; | ||
133 | XLookupString(&event, keychar, 1, &ks, 0); | ||
134 | |||
135 | if (ks == XK_Return) { | ||
136 | m_screen.currentWorkspace()->setName(m_textbox.text()); | ||
137 | m_screen.updateWorkspaceNamesAtom(); | ||
138 | Fluxbox::instance()->save_rc(); | ||
139 | delete this; // end this | ||
140 | } else if (ks == XK_Escape) | ||
141 | delete this; // end this | ||
142 | } | ||
diff --git a/src/SetWorkspaceName.hh b/src/SetWorkspaceName.hh new file mode 100644 index 0000000..50e827f --- /dev/null +++ b/src/SetWorkspaceName.hh | |||
@@ -0,0 +1,56 @@ | |||
1 | // SetWorkspaceName.hh for Fluxbox | ||
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net) | ||
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 | // $Id: SetWorkspaceName.hh,v 1.1 2003/08/26 23:48:19 fluxgen Exp $ | ||
23 | |||
24 | #ifndef SETWORKSPACENAME_HH | ||
25 | #define SETWORKSPACENAME_HH | ||
26 | |||
27 | #include "FbTk/TextBox.hh" | ||
28 | #include "FbTk/TextButton.hh" | ||
29 | #include "FbTk/Font.hh" | ||
30 | |||
31 | class BScreen; | ||
32 | |||
33 | class SetWorkspaceName: public FbTk::FbWindow, public FbTk::EventHandler { | ||
34 | public: | ||
35 | explicit SetWorkspaceName(BScreen &screen); | ||
36 | virtual ~SetWorkspaceName(); | ||
37 | |||
38 | void show(); | ||
39 | void hide(); | ||
40 | |||
41 | void motionNotifyEvent(XMotionEvent &event); | ||
42 | void buttonPressEvent(XButtonEvent &event); | ||
43 | void handleEvent(XEvent &event); | ||
44 | void keyPressEvent(XKeyEvent &event); | ||
45 | |||
46 | private: | ||
47 | FbTk::TextBox m_textbox; | ||
48 | FbTk::TextButton m_label; | ||
49 | FbTk::Font m_font; | ||
50 | GC m_gc; | ||
51 | BScreen &m_screen; | ||
52 | int m_move_x, m_move_y; | ||
53 | }; | ||
54 | |||
55 | |||
56 | #endif // SETWORKSPACENAME_HH | ||