aboutsummaryrefslogtreecommitdiff
path: root/src/SetWorkspaceName.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/SetWorkspaceName.cc')
-rw-r--r--src/SetWorkspaceName.cc142
1 files changed, 142 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>
38using namespace std;
39
40SetWorkspaceName::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
81SetWorkspaceName::~SetWorkspaceName() {
82 FbTk::EventManager::instance()->remove(*this);
83 if (m_gc)
84 XFreeGC(FbTk::App::instance()->display(), m_gc);
85
86 hide();
87}
88
89void 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
97void 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
107void 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
113void 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
121void 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
127void 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}