using ArrowButton for arrows in toolbar

This commit is contained in:
fluxgen 2002-12-13 20:37:55 +00:00
parent f018f1f99e
commit c5023fd193
2 changed files with 69 additions and 176 deletions

View file

@ -1,8 +1,8 @@
// Toolbar.cc for Fluxbox // Toolbar.cc for Fluxbox
// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) // Copyright (c) 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// //
// Toolbar.cc for Blackbox - an X11 Window manager // Toolbar.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) // Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: Toolbar.cc,v 1.49 2002/12/04 22:36:47 fluxgen Exp $ // $Id: Toolbar.cc,v 1.50 2002/12/13 20:37:55 fluxgen Exp $
#include "Toolbar.hh" #include "Toolbar.hh"
@ -39,6 +39,8 @@
#include "ToolbarTheme.hh" #include "ToolbarTheme.hh"
#include "EventManager.hh" #include "EventManager.hh"
#include "Text.hh" #include "Text.hh"
#include "ArrowButton.hh"
#include "SimpleCommand.hh"
// use GNU extensions // use GNU extensions
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
@ -74,68 +76,62 @@ using namespace std;
Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num): Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num):
window(screen_num, // screen (parent) window(screen_num, // screen (parent)
0, 0, // pos 0, 0, // pos
1, 1, // 1, 1, // size
// event mask
ButtonPressMask | ButtonReleaseMask | ButtonPressMask | ButtonReleaseMask |
EnterWindowMask | LeaveWindowMask, EnterWindowMask | LeaveWindowMask,
true), // override redirect true), // override redirect
workspace_label(window, // parent workspace_label(window, // parent
0, 0, //pos 0, 0, //pos
1, 1, // size 1, 1, // size
// event mask
ButtonPressMask | ButtonReleaseMask | ButtonPressMask | ButtonReleaseMask |
ExposureMask | KeyPressMask), ExposureMask | KeyPressMask),
window_label(window, // parent window_label(window, // parent
0, 0, // pos 0, 0, // pos
1, 1, // size 1, 1, // size
// event mask
ButtonPressMask | ButtonReleaseMask | ButtonPressMask | ButtonReleaseMask |
ExposureMask), ExposureMask),
clock (window, //parent clock (window, //parent
0, 0, // pos 0, 0, // pos
1, 1, // size 1, 1, // size
// event mask
ButtonPressMask | ButtonReleaseMask | ButtonPressMask | ButtonReleaseMask |
ExposureMask), ExposureMask),
psbutton(window, // parent psbutton(ArrowButton::LEFT, // arrow type
window, // parent
0, 0, // pos 0, 0, // pos
1, 1, // size 1, 1), // size
ButtonPressMask | ButtonReleaseMask | nsbutton(ArrowButton::RIGHT, // arrow type
ExposureMask), window, // parent
nsbutton(window, 0, 0, // pos
0, 0, 1, 1), // size
1, 1, pwbutton(ArrowButton::LEFT, // arrow type
ButtonPressMask | ButtonReleaseMask | window, // parent
ExposureMask), 0, 0, // pos
pwbutton(window, 1, 1), // size
0, 0, nwbutton(ArrowButton::RIGHT, // arrow type
1, 1, window, // parent
ButtonPressMask | ButtonReleaseMask | 0, 0, // pos
ExposureMask), 1, 1) // size
nwbutton(window,
0, 0,
1, 1,
ButtonPressMask | ButtonReleaseMask |
ExposureMask)
{ {
FbTk::EventManager &evm = *FbTk::EventManager::instance(); FbTk::EventManager &evm = *FbTk::EventManager::instance();
// add windows to eventmanager
evm.add(evh, window); evm.add(evh, window);
evm.add(evh, workspace_label); evm.add(evh, workspace_label);
evm.add(evh, window_label); evm.add(evh, window_label);
evm.add(evh, clock); evm.add(evh, clock);
evm.add(evh, psbutton);
evm.add(evh, nsbutton);
evm.add(evh, pwbutton);
evm.add(evh, nwbutton);
} }
Toolbar::Frame::~Frame() { Toolbar::Frame::~Frame() {
FbTk::EventManager &evm = *FbTk::EventManager::instance(); FbTk::EventManager &evm = *FbTk::EventManager::instance();
// remove windows from eventmanager
evm.remove(window); evm.remove(window);
evm.remove(workspace_label); evm.remove(workspace_label);
evm.remove(window_label); evm.remove(window_label);
evm.remove(clock); evm.remove(clock);
evm.remove(psbutton);
evm.remove(nsbutton);
evm.remove(pwbutton);
evm.remove(nwbutton);
} }
Toolbar::Toolbar(BScreen *scrn, size_t width): Toolbar::Toolbar(BScreen *scrn, size_t width):
@ -185,6 +181,16 @@ Toolbar::Toolbar(BScreen *scrn, size_t width):
XMapSubwindows(display, frame.window.window()); XMapSubwindows(display, frame.window.window());
frame.window.show(); frame.window.show();
// finaly: setup Commands for the buttons in the frame
FbTk::RefCount<FbTk::Command> nextworkspace(new FbTk::SimpleCommand<BScreen>(*screen(), &BScreen::nextWorkspace));
FbTk::RefCount<FbTk::Command> prevworkspace(new FbTk::SimpleCommand<BScreen>(*screen(), &BScreen::prevWorkspace));
FbTk::RefCount<FbTk::Command> nextwindow(new FbTk::SimpleCommand<BScreen>(*screen(), &BScreen::nextFocus));
FbTk::RefCount<FbTk::Command> prevwindow(new FbTk::SimpleCommand<BScreen>(*screen(), &BScreen::prevFocus));
frame.psbutton.setOnClick(prevworkspace);
frame.nsbutton.setOnClick(nextworkspace);
frame.pwbutton.setOnClick(prevwindow);
frame.nwbutton.setOnClick(nextwindow);
reconfigure(); reconfigure();
} }
@ -434,13 +440,25 @@ void Toolbar::reconfigure() {
if (tmp) if (tmp)
image_ctrl.removeImage(tmp); image_ctrl.removeImage(tmp);
// pressed button pixmap
tmp = frame.pbutton; tmp = frame.pbutton;
texture = &(m_theme.pressedButton()); texture = &(m_theme.pressedButton());
if (texture->type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { if (texture->type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
frame.pbutton = None; frame.pbutton = None;
} else } else {
frame.pbutton = frame.pbutton =
image_ctrl.renderImage(frame.button_w, frame.button_w, *texture); image_ctrl.renderImage(frame.button_w, frame.button_w, *texture);
frame.psbutton.setPressedPixmap(frame.pbutton);
frame.nsbutton.setPressedPixmap(frame.pbutton);
frame.pwbutton.setPressedPixmap(frame.pbutton);
frame.nwbutton.setPressedPixmap(frame.pbutton);
}
// setup button gc
frame.psbutton.setGC(m_theme.buttonPicGC());
frame.nsbutton.setGC(m_theme.buttonPicGC());
frame.pwbutton.setGC(m_theme.buttonPicGC());
frame.nwbutton.setGC(m_theme.buttonPicGC());
if (tmp) if (tmp)
image_ctrl.removeImage(tmp); image_ctrl.removeImage(tmp);
@ -458,10 +476,6 @@ void Toolbar::reconfigure() {
redrawWindowLabel(); redrawWindowLabel();
redrawWorkspaceLabel(); redrawWorkspaceLabel();
redrawPrevWorkspaceButton();
redrawNextWorkspaceButton();
redrawPrevWindowButton();
redrawNextWindowButton();
checkClock(true); checkClock(true);
m_toolbarmenu.reconfigure(); m_toolbarmenu.reconfigure();
@ -646,90 +660,6 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) {
dx, dy); dx, dy);
} }
void Toolbar::redrawPrevWorkspaceButton(bool pressed, bool redraw) {
if (redraw) {
drawButtonBase(frame.psbutton, pressed);
}
int hh = frame.button_w / 2, hw = frame.button_w / 2;
XPoint pts[3];
pts[0].x = hw - 2; pts[0].y = hh;
pts[1].x = 4; pts[1].y = 2;
pts[2].x = 0; pts[2].y = -4;
XFillPolygon(display, frame.psbutton.window(), m_theme.buttonPicGC(),
pts, 3, Convex, CoordModePrevious);
}
void Toolbar::redrawNextWorkspaceButton(bool pressed, bool redraw) {
if (redraw) {
drawButtonBase(frame.nsbutton, pressed);
}
int hh = frame.button_w / 2, hw = frame.button_w / 2;
XPoint pts[3];
pts[0].x = hw - 2; pts[0].y = hh - 2;
pts[1].x = 4; pts[1].y = 2;
pts[2].x = -4; pts[2].y = 2;
XFillPolygon(display, frame.nsbutton.window(), m_theme.buttonPicGC(),
pts, 3, Convex, CoordModePrevious);
}
void Toolbar::redrawPrevWindowButton(bool pressed, bool redraw) {
if (redraw) {
drawButtonBase(frame.pwbutton, pressed);
}
int hh = frame.button_w / 2, hw = frame.button_w / 2;
XPoint pts[3];
pts[0].x = hw - 2; pts[0].y = hh;
pts[1].x = 4; pts[1].y = 2;
pts[2].x = 0; pts[2].y = -4;
XFillPolygon(display, frame.pwbutton.window(), m_theme.buttonPicGC(),
pts, 3, Convex, CoordModePrevious);
}
void Toolbar::redrawNextWindowButton(bool pressed, bool redraw) {
if (redraw) {
drawButtonBase(frame.nwbutton, pressed);
}
int hh = frame.button_w / 2, hw = frame.button_w / 2;
XPoint pts[3];
pts[0].x = hw - 2; pts[0].y = hh - 2;
pts[1].x = 4; pts[1].y = 2;
pts[2].x = -4; pts[2].y = 2;
XFillPolygon(display, frame.nwbutton.window(), m_theme.buttonPicGC(),
pts, 3, Convex, CoordModePrevious);
}
void Toolbar::drawButtonBase(FbTk::FbWindow &win, bool pressed) {
if (pressed) {
if (frame.pbutton)
win.setBackgroundPixmap(frame.pbutton);
else
win.setBackgroundColor(m_theme.pressedButton().color());
} else {
if (frame.button)
win.setBackgroundPixmap(frame.button);
else
win.setBackgroundColor(m_theme.button().color());
}
win.clear();
}
void Toolbar::edit() { void Toolbar::edit() {
Window window; Window window;
int foo; int foo;
@ -762,15 +692,7 @@ void Toolbar::edit() {
void Toolbar::buttonPressEvent(XButtonEvent &be) { void Toolbar::buttonPressEvent(XButtonEvent &be) {
FluxboxWindow *fluxboxwin=0; FluxboxWindow *fluxboxwin=0;
if (be.button == 1) { if (be.button == 1) {
if (be.window == frame.psbutton) if ( m_iconbar.get() != 0 ) {
redrawPrevWorkspaceButton(true, true);
else if (be.window == frame.nsbutton)
redrawNextWorkspaceButton(true, true);
else if (be.window == frame.pwbutton)
redrawPrevWindowButton(true, true);
else if (be.window == frame.nwbutton)
redrawNextWindowButton(true, true);
else if ( m_iconbar.get() != 0 ) {
if ( (fluxboxwin = m_iconbar->findWindow(be.window)) ) if ( (fluxboxwin = m_iconbar->findWindow(be.window)) )
fluxboxwin->deiconify(); fluxboxwin->deiconify();
} }
@ -834,31 +756,7 @@ void Toolbar::buttonPressEvent(XButtonEvent &be) {
void Toolbar::buttonReleaseEvent(XButtonEvent &re) { void Toolbar::buttonReleaseEvent(XButtonEvent &re) {
if (re.button == 1) { if (re.button == 1) {
if (re.window == frame.psbutton) { if (re.window == frame.workspace_label) {
redrawPrevWorkspaceButton(false, true);
if (re.x >= 0 && re.x < (signed) frame.button_w &&
re.y >= 0 && re.y < (signed) frame.button_w)
screen()->prevWorkspace(1);
} else if (re.window == frame.nsbutton) {
redrawNextWorkspaceButton(false, true);
if (re.x >= 0 && re.x < (signed) frame.button_w &&
re.y >= 0 && re.y < (signed) frame.button_w)
screen()->nextWorkspace(1);
} else if (re.window == frame.pwbutton) {
redrawPrevWindowButton(false, true);
if (re.x >= 0 && re.x < (signed) frame.button_w &&
re.y >= 0 && re.y < (signed) frame.button_w)
screen()->prevFocus();
} else if (re.window == frame.nwbutton) {
redrawNextWindowButton(false, true);
if (re.x >= 0 && re.x < (signed) frame.button_w &&
re.y >= 0 && re.y < (signed) frame.button_w)
screen()->nextFocus();
} else if (re.window == frame.workspace_label) {
Basemenu *menu = screen()->getWorkspacemenu(); Basemenu *menu = screen()->getWorkspacemenu();
//move the workspace label and make it visible //move the workspace label and make it visible
menu->move(re.x_root, re.y_root); menu->move(re.x_root, re.y_root);
@ -923,11 +821,6 @@ void Toolbar::exposeEvent(XExposeEvent &ee) {
checkClock(true); checkClock(true);
else if (ee.window == frame.workspace_label && (! editing)) else if (ee.window == frame.workspace_label && (! editing))
redrawWorkspaceLabel(); redrawWorkspaceLabel();
else if (ee.window == frame.window_label) redrawWindowLabel();
else if (ee.window == frame.psbutton) redrawPrevWorkspaceButton();
else if (ee.window == frame.nsbutton) redrawNextWorkspaceButton();
else if (ee.window == frame.pwbutton) redrawPrevWindowButton();
else if (ee.window == frame.nwbutton) redrawNextWindowButton();
else if (m_iconbar.get() != 0) else if (m_iconbar.get() != 0)
m_iconbar->exposeEvent(&ee); m_iconbar->exposeEvent(&ee);
} }

View file

@ -1,5 +1,5 @@
// Toolbar.hh for Fluxbox // Toolbar.hh for Fluxbox
// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org) // Copyright (c) 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// //
// Toolbar.hh for Blackbox - an X11 Window manager // Toolbar.hh for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: Toolbar.hh,v 1.17 2002/12/03 16:54:13 fluxgen Exp $ // $Id: Toolbar.hh,v 1.18 2002/12/13 20:36:36 fluxgen Exp $
#ifndef TOOLBAR_HH #ifndef TOOLBAR_HH
#define TOOLBAR_HH #define TOOLBAR_HH
@ -33,6 +33,7 @@
#include "ToolbarTheme.hh" #include "ToolbarTheme.hh"
#include "EventHandler.hh" #include "EventHandler.hh"
#include "FbWindow.hh" #include "FbWindow.hh"
#include "ArrowButton.hh"
#include <memory> #include <memory>
@ -90,24 +91,27 @@ private:
}; };
/// The toolbar.
/** /**
the toolbar. Handles iconbar, workspace name view and clock view
*/ */
class Toolbar : public TimeoutHandler, public FbTk::EventHandler { class Toolbar : public TimeoutHandler, public FbTk::EventHandler {
public: public:
/**
Toolbar placement on the screen ///Toolbar placement on the screen
*/
enum Placement{ enum Placement{
// top bottom placement // top and bottom placement
TOPLEFT = 1, BOTTOMLEFT, TOPCENTER, TOPLEFT = 1, BOTTOMLEFT, TOPCENTER,
BOTTOMCENTER, TOPRIGHT, BOTTOMRIGHT, BOTTOMCENTER, TOPRIGHT, BOTTOMRIGHT,
// left right placement // left and right placement
LEFTCENTER, LEFTBOTTOM, LEFTTOP, LEFTCENTER, LEFTBOTTOM, LEFTTOP,
RIGHTCENTER, RIGHTBOTTOM, RIGHTTOP RIGHTCENTER, RIGHTBOTTOM, RIGHTTOP
}; };
/// create a toolbar on the screen with specific width
explicit Toolbar(BScreen *screen, size_t width = 200); explicit Toolbar(BScreen *screen, size_t width = 200);
/// destructor
virtual ~Toolbar(); virtual ~Toolbar();
/// add icon to iconbar /// add icon to iconbar
@ -152,10 +156,6 @@ public:
void redrawWindowLabel(bool redraw= false); void redrawWindowLabel(bool redraw= false);
void redrawWorkspaceLabel(bool redraw= false); void redrawWorkspaceLabel(bool redraw= false);
void redrawPrevWorkspaceButton(bool pressed = false, bool redraw = false);
void redrawNextWorkspaceButton(bool pressed = false, bool redraw = false);
void redrawPrevWindowButton(bool pressed = false, bool redraw = false);
void redrawNextWindowButton(bool pressed = false, bool redraw = false);
/// enter edit mode on workspace label /// enter edit mode on workspace label
void edit(); void edit();
void reconfigure(); void reconfigure();
@ -166,7 +166,6 @@ public:
private: private:
void drawButtonBase(FbTk::FbWindow &win, bool pressed);
bool on_top; ///< always on top bool on_top; ///< always on top
bool editing; ///< edit workspace label mode bool editing; ///< edit workspace label mode
@ -174,12 +173,13 @@ private:
bool do_auto_hide; ///< do we auto hide bool do_auto_hide; ///< do we auto hide
Display *display; ///< display connection Display *display; ///< display connection
/// Toolbar frame
struct Frame { struct Frame {
Frame(FbTk::EventHandler &evh, int screen_num); Frame(FbTk::EventHandler &evh, int screen_num);
~Frame(); ~Frame();
Pixmap base, label, wlabel, clk, button, pbutton; Pixmap base, label, wlabel, clk, button, pbutton;
FbTk::FbWindow window, workspace_label, window_label, clock, psbutton, nsbutton, FbTk::FbWindow window, workspace_label, window_label, clock;
pwbutton, nwbutton; ArrowButton psbutton, nsbutton, pwbutton, nwbutton;
int x, y, x_hidden, y_hidden, hour, minute, grab_x, grab_y; int x, y, x_hidden, y_hidden, hour, minute, grab_x, grab_y;
unsigned int width, height, window_label_w, workspace_label_w, clock_w, unsigned int width, height, window_label_w, workspace_label_w, clock_w,