Feature #3602124: 'LHalf' and 'RHalf' buttons to the titlebar

First draft of feature request of #3602124: Having 2 buttons in the titlebar
which allow quick positioning of a Window into the left or right half of the
current monitor.
This commit is contained in:
Mathias Gumz 2013-02-06 13:47:11 +01:00
parent 94fddc09c0
commit 34343bb20b
6 changed files with 85 additions and 19 deletions

View file

@ -108,6 +108,12 @@ getString() const {
case WinButton::MENUICON:
retval.append("MenuIcon");
break;
case WinButton::LEFT_HALF:
retval.append("LHalf");
break;
case WinButton::RIGHT_HALF:
retval.append("RHalf");
break;
default:
break;
}
@ -142,6 +148,10 @@ setFromString(char const *strval) {
m_value.push_back(WinButton::MENUICON);
else if (v == "close")
m_value.push_back(WinButton::CLOSE);
else if (v == "lhalf")
m_value.push_back(WinButton::LEFT_HALF);
else if (v == "rhalf")
m_value.push_back(WinButton::RIGHT_HALF);
}
}

View file

@ -137,6 +137,10 @@ Pixmap WinButton::getPixmap(const FbTk::ThemeProxy<WinButtonTheme> &theme) const
return theme->titlePixmap().pixmap().drawable();
else
return theme->menuiconPixmap().pixmap().drawable();
case LEFT_HALF:
return theme->leftHalfPixmap().pixmap().drawable();
case RIGHT_HALF:
return theme->rightHalfPixmap().pixmap().drawable();
default:
return None;
}
@ -160,18 +164,14 @@ void WinButton::drawType() {
// otherwise draw old style imagery
switch (m_type) {
case MAXIMIZE:
// if no pixmap was used, use old style
if (gc() == 0) // must have valid graphic context
return;
drawRectangle(gc(),
2, 2, width() - 5, height() - 5);
drawLine(gc(),
2, 3, width() - 3, 3);
drawRectangle(gc(), 2, 2, width() - 5, height() - 5);
drawLine(gc(), 2, 3, width() - 3, 3);
break;
case MINIMIZE:
drawRectangle(gc(), 2, height() - 5, width() - 5, 2);
break;
case STICK:
// width/4 != width/2, so we use /4*2 so that it's properly centred
if (m_listen_to.isStuck()) {
@ -184,6 +184,7 @@ void WinButton::drawType() {
width()/10*2 + oddW, height()/10*2 + oddH);
}
break;
case CLOSE:
drawLine(gc(),
2, 2,
@ -199,15 +200,12 @@ void WinButton::drawType() {
// XFree86 Version 4.3.0.1 (Debian 4.3.0.dfsg.1-1 20040428170728)
// (X Protocol Version 11, Revision 0, Release 6.6)
drawLine(gc(),
2, height() - 3,
width() - 3, 2);
drawLine(gc(), 2, height() - 3, width() - 3, 2);
break;
case SHADE:
case SHADE:
{
int size = width() - 5 - oddW;
drawRectangle(gc(), 2, 2, size, 2);
// draw a one-quarter triangle below the rectangle
@ -220,6 +218,7 @@ void WinButton::drawType() {
break;
}
case MENUICON:
if (m_icon_pixmap.drawable()) {
@ -242,10 +241,16 @@ void WinButton::drawType() {
for (unsigned int y = height()/3; y <= height() - height()/3; y+=3) {
drawLine(gc(), width()/4, y, width() - width()/4 - oddW - 1, y);
}
drawRectangle(gc(),
2, 2, width() - 5, height() - 5);
drawRectangle(gc(), 2, 2, width() - 5, height() - 5);
}
break;
case LEFT_HALF:
fillRectangle(gc(), 2, 2, (width() / 2) - oddW, height() - 4);
break;
case RIGHT_HALF:
fillRectangle(gc(), width() / 2, 2, (width() / 2) - 2 + oddW, height() - 4);
break;
}
}

View file

@ -38,7 +38,17 @@ template <class T> class ThemeProxy;
class WinButton:public FbTk::Button, public FbTk::SignalTracker {
public:
/// draw type for the button
enum Type {MAXIMIZE, MINIMIZE, SHADE, STICK, CLOSE, MENUICON};
enum Type {
MAXIMIZE,
MINIMIZE,
SHADE,
STICK,
CLOSE,
MENUICON,
LEFT_HALF,
RIGHT_HALF
};
WinButton(FluxboxWindow &listen_to,
FbTk::ThemeProxy<WinButtonTheme> &theme,
FbTk::ThemeProxy<WinButtonTheme> &pressed,
@ -66,7 +76,7 @@ private:
FbTk::FbPixmap m_icon_pixmap;
FbTk::FbPixmap m_icon_mask;
bool overrode_bg, overrode_pressed;
};

View file

@ -52,6 +52,10 @@ WinButtonTheme::WinButtonTheme(int screen_num,
"Window.Stick" + altextra + ".Pixmap"),
m_stuck_pm(*this, "window.stuck" + extra + ".pixmap",
"Window.Stuck" + altextra + ".Pixmap"),
m_lefthalf_pm(*this, "window.lhalf" + extra + ".pixmap",
"Window.LHalf" + altextra + ".Pixmap"),
m_righthalf_pm(*this, "window.rhalf" + extra + ".pixmap",
"Window.RHalf" + altextra + ".Pixmap"),
m_frame_theme(frame_theme) {
FbTk::ThemeManager::instance().loadTheme(*this);
@ -82,5 +86,7 @@ void WinButtonTheme::reconfigTheme() {
m_title_pm->scale(size, size);
m_stick_pm->scale(size, size);
m_stuck_pm->scale(size, size);
m_lefthalf_pm->scale(size, size);
m_righthalf_pm->scale(size, size);
}

View file

@ -62,10 +62,18 @@ public:
const FbTk::PixmapWithMask &menuiconPixmap() const { return *m_menuicon_pm; }
FbTk::PixmapWithMask &menuiconPixmap() { return *m_menuicon_pm; }
FbTk::PixmapWithMask &titlePixmap() { return *m_title_pm; }
const FbTk::PixmapWithMask &titlePixmap() const { return *m_title_pm; }
FbTk::PixmapWithMask &leftHalfPixmap() { return *m_lefthalf_pm; }
const FbTk::PixmapWithMask &leftHalfPixmap() const { return *m_lefthalf_pm; }
FbTk::PixmapWithMask &rightHalfPixmap() { return *m_righthalf_pm; }
const FbTk::PixmapWithMask &rightHalfPixmap() const { return *m_righthalf_pm; }
virtual FbTk::Signal<> &reconfigSig() { return FbTk::Theme::reconfigSig(); }
virtual WinButtonTheme &operator *() { return *this; }
@ -75,7 +83,7 @@ private:
FbTk::ThemeItem<FbTk::PixmapWithMask> m_close_pm, m_maximize_pm,
m_iconify_pm, m_shade_pm, m_unshade_pm, m_menuicon_pm, m_title_pm,
m_stick_pm, m_stuck_pm;
m_stick_pm, m_stuck_pm, m_lefthalf_pm, m_righthalf_pm;
FbTk::ThemeProxy<FbWinFrameTheme> &m_frame_theme;
};

View file

@ -48,6 +48,7 @@
#include "FbTk/StringUtil.hh"
#include "FbTk/Compose.hh"
#include "FbTk/CommandParser.hh"
#include "FbTk/EventManager.hh"
#include "FbTk/KeyUtil.hh"
#include "FbTk/SimpleCommand.hh"
@ -3600,6 +3601,32 @@ void FluxboxWindow::updateButtons() {
winbtn->setOnClick(show_menu_cmd);
}
break;
case WinButton::LEFT_HALF:
{
winbtn = new WinButton(*this, m_button_theme,
screen().pressedWinButtonTheme(),
dir[i],
frame().titlebar(),
0, 0, 10, 10);
CommandRef lhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 0 0} {ResizeTo 50% 100%}"));
winbtn->setOnClick(lhalf_cmd);
}
break;
case WinButton::RIGHT_HALF:
{
winbtn = new WinButton(*this, m_button_theme,
screen().pressedWinButtonTheme(),
dir[i],
frame().titlebar(),
0, 0, 10, 10);
CommandRef rhalf_cmd(FbTk::CommandParser<void>::instance().parse("MacroCmd {MoveTo 50% 0} {ResizeTo 50% 100%}"));
winbtn->setOnClick(rhalf_cmd);
}
break;
}