move FluxboxWindow::applyDecorations() to FbWinFrame

This commit is contained in:
Mark Tiefenbruck 2008-05-24 01:03:59 -07:00
parent 5ecb192a9c
commit 46bca62a9c
6 changed files with 137 additions and 146 deletions

View file

@ -43,21 +43,28 @@
namespace FbTk { namespace FbTk {
FbWindow::FbWindow():FbDrawable(), m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0), FbWindow::FbWindow():
m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true), FbDrawable(),
m_lastbg_color_set(false), m_lastbg_color(0), m_lastbg_pm(0), m_renderer(0) { m_parent(0), m_screen_num(0), m_window(0),
m_x(0), m_y(0), m_width(0), m_height(0),
m_border_width(0), m_border_color(0),
m_depth(0), m_destroy(true),
m_lastbg_color_set(false), m_lastbg_color(0), m_lastbg_pm(0),
m_renderer(0) {
} }
FbWindow::FbWindow(const FbWindow& the_copy):FbDrawable(), FbWindow::FbWindow(const FbWindow& the_copy):
m_parent(the_copy.parent()), FbDrawable(),
m_screen_num(the_copy.screenNumber()), m_window(the_copy.window()), m_parent(the_copy.parent()),
m_x(the_copy.x()), m_y(the_copy.y()), m_screen_num(the_copy.screenNumber()), m_window(the_copy.window()),
m_width(the_copy.width()), m_height(the_copy.height()), m_x(the_copy.x()), m_y(the_copy.y()),
m_border_width(the_copy.borderWidth()), m_width(the_copy.width()), m_height(the_copy.height()),
m_depth(the_copy.depth()), m_destroy(true), m_border_width(the_copy.borderWidth()),
m_lastbg_color_set(false), m_lastbg_color(0), m_border_color(the_copy.borderColor()),
m_lastbg_pm(0), m_renderer(the_copy.m_renderer) { m_depth(the_copy.depth()), m_destroy(true),
m_lastbg_color_set(false), m_lastbg_color(0), m_lastbg_pm(0),
m_renderer(the_copy.m_renderer) {
the_copy.m_window = 0; the_copy.m_window = 0;
} }
@ -100,17 +107,14 @@ FbWindow::FbWindow(const FbWindow &parent,
}; };
FbWindow::FbWindow(Window client):FbDrawable(), m_parent(0), FbWindow::FbWindow(Window client):
m_screen_num(0), FbDrawable(),
m_window(0), m_parent(0), m_screen_num(0), m_window(0),
m_x(0), m_y(0), m_x(0), m_y(0), m_width(1), m_height(1),
m_width(1), m_height(1), m_border_width(0), m_border_color(0),
m_border_width(0), m_depth(0), m_destroy(false), // don't destroy this window
m_depth(0), m_lastbg_color_set(false), m_lastbg_color(0), m_lastbg_pm(0),
m_destroy(false), // don't destroy this window m_renderer(0) {
m_lastbg_color_set(false), m_lastbg_color(0),
m_lastbg_pm(0), m_renderer(0) {
setNew(client); setNew(client);
} }
@ -235,6 +239,7 @@ void FbWindow::updateBackground(bool only_if_alpha) {
void FbWindow::setBorderColor(const FbTk::Color &border_color) { void FbWindow::setBorderColor(const FbTk::Color &border_color) {
XSetWindowBorder(display(), m_window, border_color.pixel()); XSetWindowBorder(display(), m_window, border_color.pixel());
m_border_color = border_color.pixel();
} }
void FbWindow::setBorderWidth(unsigned int size) { void FbWindow::setBorderWidth(unsigned int size) {
@ -373,6 +378,7 @@ FbWindow &FbWindow::operator = (const FbWindow &win) {
m_width = win.width(); m_width = win.width();
m_height = win.height(); m_height = win.height();
m_border_width = win.borderWidth(); m_border_width = win.borderWidth();
m_border_color = win.borderColor();
m_depth = win.depth(); m_depth = win.depth();
// take over this window // take over this window
win.m_window = 0; win.m_window = 0;
@ -601,6 +607,7 @@ void FbWindow::create(Window parent, int x, int y,
m_border_width = 0; m_border_width = 0;
m_border_color = 0;
long valmask = CWEventMask; long valmask = CWEventMask;
XSetWindowAttributes values; XSetWindowAttributes values;

View file

@ -177,6 +177,7 @@ public:
unsigned int width() const { return m_width; } unsigned int width() const { return m_width; }
unsigned int height() const { return m_height; } unsigned int height() const { return m_height; }
unsigned int borderWidth() const { return m_border_width; } unsigned int borderWidth() const { return m_border_width; }
unsigned long borderColor() const { return m_border_color; }
unsigned int depth() const { return m_depth; } unsigned int depth() const { return m_depth; }
unsigned char alpha() const; unsigned char alpha() const;
int screenNumber() const; int screenNumber() const;
@ -225,6 +226,7 @@ private:
int m_x, m_y; ///< position of window int m_x, m_y; ///< position of window
unsigned int m_width, m_height; ///< size of window unsigned int m_width, m_height; ///< size of window
unsigned int m_border_width; ///< border size unsigned int m_border_width; ///< border size
unsigned long m_border_color; ///< border color
unsigned int m_depth; ///< bit depth unsigned int m_depth; ///< bit depth
bool m_destroy; ///< wheter the x window was created before bool m_destroy; ///< wheter the x window was created before
std::auto_ptr<FbTk::Transparent> m_transparent; std::auto_ptr<FbTk::Transparent> m_transparent;

View file

@ -487,12 +487,7 @@ void FbWinFrame::setFocus(bool newvalue) {
} }
} }
if (m_decoration_mask & DECORM_BORDER && setBorderWidth();
(theme().focusedTheme()->border().width() !=
theme().unfocusedTheme()->border().width() ||
theme().focusedTheme()->border().color().pixel() !=
theme().unfocusedTheme()->border().color().pixel()))
setBorderWidth(theme()->border().width());
applyAll(); applyAll();
clearAll(); clearAll();
@ -759,28 +754,6 @@ bool FbWinFrame::showHandle() {
return true; return true;
} }
bool FbWinFrame::hideAllDecorations() {
bool changed = false;
changed |= hideHandle();
changed |= hideTitlebar();
// resize done by hide*
reconfigure();
return changed;
}
bool FbWinFrame::showAllDecorations() {
bool changed = false;
if (!m_use_handle)
changed |= showHandle();
if (!m_use_titlebar)
changed |= showTitlebar();
// resize shouldn't be necessary
reconfigure();
return changed;
}
/** /**
Set new event handler for the frame's windows Set new event handler for the frame's windows
*/ */
@ -871,8 +844,7 @@ void FbWinFrame::reconfigure() {
gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw, false); gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw, false);
m_bevel = theme()->bevelWidth(); m_bevel = theme()->bevelWidth();
setBorderWidth(m_decoration_mask & DECORM_BORDER ? setBorderWidth();
theme()->border().width() : 0);
if (m_decoration_mask & DECORM_HANDLE && theme()->handleWidth() != 0) if (m_decoration_mask & DECORM_HANDLE && theme()->handleWidth() != 0)
showHandle(); showHandle();
@ -1439,14 +1411,78 @@ void FbWinFrame::applyTabContainer() {
} }
} }
void FbWinFrame::setBorderWidth(unsigned int border_width) { void FbWinFrame::applyDecorations() {
int bw_changes = 0; int grav_x=0, grav_y=0;
// negate gravity
gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw,
false);
bool client_move = setBorderWidth(false);
// tab deocration only affects if we're external
// must do before the setTabMode in case it goes
// to external and is meant to be hidden
if (m_decoration_mask & DECORM_TAB)
client_move |= showTabs();
else
client_move |= hideTabs();
// we rely on frame not doing anything if it is already shown/hidden
if (m_decoration_mask & DECORM_TITLEBAR) {
client_move |= showTitlebar();
if (m_screen.getDefaultInternalTabs())
client_move |= setTabMode(INTERNAL);
else
client_move |= setTabMode(EXTERNAL);
} else {
client_move |= hideTitlebar();
if (m_decoration_mask & DECORM_TAB)
client_move |= setTabMode(EXTERNAL);
}
if (m_decoration_mask & DECORM_HANDLE)
client_move |= showHandle();
else
client_move |= hideHandle();
// apply gravity once more
gravityTranslate(grav_x, grav_y, m_active_gravity, m_active_orig_client_bw,
false);
// if the location changes, shift it
if (grav_x != 0 || grav_y != 0) {
move(grav_x + x(), grav_y + y());
client_move = true;
}
reconfigure();
if (client_move)
frameExtentSig().notify();
}
bool FbWinFrame::setBorderWidth(bool do_move) {
unsigned int border_width = m_decoration_mask & DECORM_BORDER ?
theme()->border().width() : 0;
if (border_width &&
theme()->border().color().pixel() != window().borderColor()) {
window().setBorderColor(theme()->border().color());
titlebar().setBorderColor(theme()->border().color());
handle().setBorderColor(theme()->border().color());
gripLeft().setBorderColor(theme()->border().color());
gripRight().setBorderColor(theme()->border().color());
}
if (border_width == window().borderWidth())
return false;
int grav_x=0, grav_y=0; int grav_x=0, grav_y=0;
// negate gravity // negate gravity
gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw, false); if (do_move)
gravityTranslate(grav_x, grav_y, -m_active_gravity,
m_active_orig_client_bw, false);
int bw_changes = 0;
// we need to change the size of the window // we need to change the size of the window
// if the border width changes... // if the border width changes...
if (m_use_titlebar) if (m_use_titlebar)
@ -1455,21 +1491,13 @@ void FbWinFrame::setBorderWidth(unsigned int border_width) {
bw_changes += static_cast<signed>(border_width - handle().borderWidth()); bw_changes += static_cast<signed>(border_width - handle().borderWidth());
window().setBorderWidth(border_width); window().setBorderWidth(border_width);
window().setBorderColor(theme()->border().color());
setTabMode(NOTSET); setTabMode(NOTSET);
titlebar().setBorderWidth(border_width); titlebar().setBorderWidth(border_width);
titlebar().setBorderColor(theme()->border().color());
handle().setBorderWidth(border_width); handle().setBorderWidth(border_width);
handle().setBorderColor(theme()->border().color());
gripLeft().setBorderWidth(border_width); gripLeft().setBorderWidth(border_width);
gripLeft().setBorderColor(theme()->border().color());
gripRight().setBorderWidth(border_width); gripRight().setBorderWidth(border_width);
gripRight().setBorderColor(theme()->border().color());
if (bw_changes != 0) if (bw_changes != 0)
resize(width(), height() + bw_changes); resize(width(), height() + bw_changes);
@ -1477,11 +1505,16 @@ void FbWinFrame::setBorderWidth(unsigned int border_width) {
if (m_tabmode == EXTERNAL) if (m_tabmode == EXTERNAL)
alignTabs(); alignTabs();
gravityTranslate(grav_x, grav_y, m_active_gravity, m_active_orig_client_bw, false); if (do_move) {
// if the location changes, shift it frameExtentSig().notify();
if (grav_x != 0 || grav_y != 0) gravityTranslate(grav_x, grav_y, m_active_gravity,
move(grav_x + x(), grav_y + y()); m_active_orig_client_bw, false);
// if the location changes, shift it
if (grav_x != 0 || grav_y != 0)
move(grav_x + x(), grav_y + y());
}
return true;
} }
// this function translates its arguments according to win_gravity // this function translates its arguments according to win_gravity

View file

@ -25,7 +25,7 @@
#include "FbTk/FbWindow.hh" #include "FbTk/FbWindow.hh"
#include "FbTk/EventHandler.hh" #include "FbTk/EventHandler.hh"
#include "FbTk/RefCount.hh" #include "FbTk/RefCount.hh"
#include "FbTk/Observer.hh" #include "FbTk/Subject.hh"
#include "FbTk/Color.hh" #include "FbTk/Color.hh"
#include "FbTk/XLayerItem.hh" #include "FbTk/XLayerItem.hh"
#include "FbTk/TextButton.hh" #include "FbTk/TextButton.hh"
@ -186,21 +186,12 @@ public:
void removeEventHandler(); void removeEventHandler();
void setDecorationMask(unsigned int mask) { m_decoration_mask = mask; } void setDecorationMask(unsigned int mask) { m_decoration_mask = mask; }
// these return true/false for if something changed void applyDecorations();
bool hideTitlebar();
bool showTitlebar();
bool hideTabs();
bool showTabs();
bool hideHandle();
bool showHandle();
bool hideAllDecorations();
bool showAllDecorations();
// this function translates its arguments according to win_gravity // this function translates its arguments according to win_gravity
// if win_gravity is negative, it does an inverse translation // if win_gravity is negative, it does an inverse translation
void gravityTranslate(int &x, int &y, int win_gravity, unsigned int client_bw, bool move_frame = false); void gravityTranslate(int &x, int &y, int win_gravity, unsigned int client_bw, bool move_frame = false);
void setActiveGravity(int gravity, unsigned int orig_client_bw) { m_active_gravity = gravity; m_active_orig_client_bw = orig_client_bw; } void setActiveGravity(int gravity, unsigned int orig_client_bw) { m_active_gravity = gravity; m_active_orig_client_bw = orig_client_bw; }
void setBorderWidth(unsigned int borderW);
/** /**
@name Event handlers @name Event handlers
@ -266,6 +257,9 @@ public:
const FbTk::XLayerItem &layerItem() const { return m_layeritem; } const FbTk::XLayerItem &layerItem() const { return m_layeritem; }
FbTk::XLayerItem &layerItem() { return m_layeritem; } FbTk::XLayerItem &layerItem() { return m_layeritem; }
const FbTk::Subject &frameExtentSig() const { return m_frame_extent_sig; }
FbTk::Subject &frameExtentSig() { return m_frame_extent_sig; }
//@} //@}
private: private:
@ -290,6 +284,15 @@ private:
//@} //@}
// these return true/false for if something changed
bool hideTitlebar();
bool showTitlebar();
bool hideTabs();
bool showTabs();
bool hideHandle();
bool showHandle();
bool setBorderWidth(bool do_move = true);
/** /**
@name apply pixmaps depending on focus @name apply pixmaps depending on focus
*/ */
@ -332,6 +335,9 @@ private:
m_grip_left; ///< left grip m_grip_left; ///< left grip
FbTk::FbWindow m_clientarea; ///< window that sits behind client window to fill gaps @see setClientWindow FbTk::FbWindow m_clientarea; ///< window that sits behind client window to fill gaps @see setClientWindow
//@} //@}
FbTk::Subject m_frame_extent_sig;
typedef std::vector<FbTk::Button *> ButtonList; typedef std::vector<FbTk::Button *> ButtonList;
ButtonList m_buttons_left, ///< buttons to the left ButtonList m_buttons_left, ///< buttons to the left
m_buttons_right; ///< buttons to the right m_buttons_right; ///< buttons to the right

View file

@ -303,6 +303,7 @@ FluxboxWindow::FluxboxWindow(WinClient &client, FbTk::XLayer &layer):
m_resize_corner(RIGHTBOTTOM) { m_resize_corner(RIGHTBOTTOM) {
m_theme.reconfigSig().attach(this); m_theme.reconfigSig().attach(this);
m_frame.frameExtentSig().attach(this);
init(); init();
@ -501,7 +502,7 @@ void FluxboxWindow::init() {
setOnHead(screen().getCurrHead()); setOnHead(screen().getCurrHead());
// we must do this now, or else resizing may not work properly // we must do this now, or else resizing may not work properly
applyDecorations(true); applyDecorations();
Fluxbox::instance()->attachSignals(*this); Fluxbox::instance()->attachSignals(*this);
@ -601,7 +602,7 @@ void FluxboxWindow::init() {
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
m_creation_time = now.tv_sec; m_creation_time = now.tv_sec;
sendConfigureNotify(); frame().frameExtentSig().notify();
setupWindow(); setupWindow();
@ -3015,74 +3016,16 @@ void FluxboxWindow::update(FbTk::Subject *subj) {
} else if (subj == &m_theme.reconfigSig()) { } else if (subj == &m_theme.reconfigSig()) {
frame().reconfigure(); frame().reconfigure();
reconfigTheme(); reconfigTheme();
} else if (m_initialized && subj == &m_frame.frameExtentSig()) {
Fluxbox::instance()->updateFrameExtents(*this);
sendConfigureNotify();
} }
} }
// commit current decoration values to actual displayed things // commit current decoration values to actual displayed things
void FluxboxWindow::applyDecorations(bool initial) { void FluxboxWindow::applyDecorations() {
frame().clientArea().setBorderWidth(0); // client area bordered by other things
unsigned int border_width = 0;
if (decorations.border)
border_width = frame().theme()->border().width();
bool client_move = false;
// borderWidth setting handles its own gravity
if (initial || frame().window().borderWidth() != border_width) {
client_move = true;
frame().setBorderWidth(border_width);
}
int grav_x=0, grav_y=0;
// negate gravity
frame().gravityTranslate(grav_x, grav_y, -m_client->gravity(), m_client->old_bw, false);
// tab deocration only affects if we're external
// must do before the setTabMode in case it goes
// to external and is meant to be hidden
if (decorations.tab)
client_move |= frame().showTabs();
else
client_move |= frame().hideTabs();
// we rely on frame not doing anything if it is already shown/hidden
if (decorations.titlebar) {
bool change = frame().showTitlebar();
client_move |= change;
if (screen().getDefaultInternalTabs()) {
client_move |= frame().setTabMode(FbWinFrame::INTERNAL);
} else {
client_move |= frame().setTabMode(FbWinFrame::EXTERNAL);
}
} else {
client_move |= frame().hideTitlebar();
if (decorations.tab)
client_move |= frame().setTabMode(FbWinFrame::EXTERNAL);
}
if (decorations.handle) {
client_move |= frame().showHandle();
} else
client_move |= frame().hideHandle();
// apply gravity once more
frame().gravityTranslate(grav_x, grav_y, m_client->gravity(), m_client->old_bw, false);
// if the location changes, shift it
if (grav_x != 0 || grav_y != 0) {
move(grav_x + frame().x(), grav_y + frame().y());
client_move = true;
}
frame().setDecorationMask(decorationMask()); frame().setDecorationMask(decorationMask());
frame().reconfigure(); frame().applyDecorations();
if (client_move)
Fluxbox::instance()->updateFrameExtents(*this);
if (!initial && client_move)
sendConfigureNotify();
} }
void FluxboxWindow::toggleDecoration() { void FluxboxWindow::toggleDecoration() {

View file

@ -357,7 +357,7 @@ public:
/// handle Subject notifications /// handle Subject notifications
void update(FbTk::Subject *subj); void update(FbTk::Subject *subj);
void applyDecorations(bool initial = false); void applyDecorations();
void toggleDecoration(); void toggleDecoration();
unsigned int decorationMask() const; unsigned int decorationMask() const;