Skip to content

Commit

Permalink
Add a Tile submenu to the title bar menu for issue ice-wm/icewm#74.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Dec 16, 2021
1 parent 34c8ec5 commit a061b0c
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 38 deletions.
9 changes: 9 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ nobase_dist_pkgdata_DATA = \
icons/suspend_32x32.xpm \
icons/themes_16x16.xpm \
icons/themes_32x32.xpm \
icons/tilebottom_48x48.png \
icons/tilebottomleft_48x48.png \
icons/tilebottomright_48x48.png \
icons/tilecenter_48x48.png \
icons/tileleft_48x48.png \
icons/tileright_48x48.png \
icons/tiletop_48x48.png \
icons/tiletopleft_48x48.png \
icons/tiletopright_48x48.png \
icons/vim_16x16.xpm \
icons/vim_32x32.xpm \
icons/vim_48x48.xpm \
Expand Down
Binary file added lib/icons/tilebottom_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tilebottomleft_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tilebottomright_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tilecenter_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tileleft_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tileright_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tiletop_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tiletopleft_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/icons/tiletopright_48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 49 additions & 25 deletions src/decorate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,62 @@ void YFrameWindow::updateMenu() {
}

void YFrameWindow::updateSubmenus() {
YMenuItem *item = windowMenu()->findSubmenu(moveMenu);
if (item)
item->setEnabled(!isAllWorkspaces());

moveMenu->updatePopup();
moveMenu->setActionListener(this);
for (int i(0); i < moveMenu->itemCount(); i++) {
item = moveMenu->getItem(i);
if (item && item->getAction() == workspaceActionMoveTo[i]) {
bool const e(i == getWorkspace());
item->setEnabled(!e);
item->setChecked(e);
if (moveMenu) {
YMenuItem *item = windowMenu()->findSubmenu(moveMenu);
if (item) {
bool enable = !isAllWorkspaces() && 1 < workspaceCount;
item->setEnabled(enable);
if (enable) {
moveMenu->updatePopup();
moveMenu->setActionListener(this);

for (int i(0); i < moveMenu->itemCount(); i++) {
item = moveMenu->getItem(i);
if (item && item->getAction() == workspaceActionMoveTo[i]) {
bool const e(i == getWorkspace());
item->setEnabled(!e);
item->setChecked(e);
}
}
}
}
}

layerMenu->updatePopup();
layerMenu->setActionListener(this);
int layer = WinLayerCount - 1;
for (int j(0); j < layerMenu->itemCount(); j++) {
item = layerMenu->getItem(j);
YAction action = item->getAction();
while (action < layerActionSet[layer] && 0 < layer) {
--layer;
if (layerMenu) {
YMenuItem *item = windowMenu()->findSubmenu(layerMenu);
if (item) {
layerMenu->updatePopup();
layerMenu->setActionListener(this);

int layer = WinLayerCount - 1;
for (int j(0); j < layerMenu->itemCount(); j++) {
YMenuItem* item = layerMenu->getItem(j);
YAction action = item->getAction();
while (action < layerActionSet[layer] && 0 < layer) {
--layer;
}
if (action == layerActionSet[layer]) {
bool const e(layer == getActiveLayer());
item->setEnabled(!e);
item->setChecked(e);
}
}
}
if (action == layerActionSet[layer]) {
bool const e(layer == getActiveLayer());
item->setEnabled(!e);
item->setChecked(e);
}

if (tileMenu) {
YMenuItem *item = windowMenu()->findSubmenu(tileMenu);
if (item) {
bool enable = canMove();
item->setEnabled(enable);
if (enable) {
tileMenu->updatePopup();
tileMenu->setActionListener(this);
}
}
}

item = windowMenu()->findAction(actionToggleTray);
YMenuItem* item = windowMenu()->findAction(actionToggleTray);
if (item) {
bool checked = (getTrayOption() != WinTrayIgnore);
bool enabled = notbit(frameOptions(), foIgnoreTaskBar);
Expand Down
9 changes: 9 additions & 0 deletions src/wmaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ enum EAction {
actionLayerAboveAll = 241,

actionAboutClose = 243,
actionTileLeft = 245,
actionTileRight = 246,
actionTileTop = 247,
actionTileBottom = 248,
actionTileTopLeft = 249,
actionTileTopRight = 250,
actionTileBottomLeft = 251,
actionTileBottomRight = 252,
actionTileCenter = 253,
};

bool canShutdown(RebootShutdown reboot);
Expand Down
32 changes: 32 additions & 0 deletions src/wmapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ YCursor YWMApp::scrollUpPointer;
YCursor YWMApp::scrollDownPointer;

lazy<MoveMenu> moveMenu;
lazy<TileMenu> tileMenu;
lazy<LayerMenu> layerMenu;
lazily<SharedWindowList> windowListMenu;
lazy<LogoutMenu> logoutMenu;
Expand Down Expand Up @@ -554,6 +555,33 @@ void MoveMenu::updatePopup() {
}
}

void TileMenu::updatePopup() {
if (itemCount()) {
enableCommand(actionNull);
return;
}

addItem(_("Left Half"), -2, actionTileLeft, nullptr, "tileleft");
addItem(_("Right Half"), -2, actionTileRight, nullptr, "tileright");
addItem(_("Top Half"), -2, actionTileTop, nullptr, "tiletop");
addItem(_("Bottom Half"), -2, actionTileBottom, nullptr, "tilebottom");
addSeparator();
addItem(_("Top Left"), -2, actionTileTopLeft, nullptr,
"tiletopleft");
addItem(_("Top Right"), -2, actionTileTopRight, nullptr,
"tiletopright");
addItem(_("Bottom Left"), -2, actionTileBottomLeft, nullptr,
"tilebottomleft");
addItem(_("Bottom Right"), -2, actionTileBottomRight, nullptr,
"tilebottomright");
addItem(_("Center"), -2, actionTileCenter, nullptr, "tilecenter");
addSeparator();
addItem(_("T_ile Horizontally"), -2,
KEY_NAME(gKeySysTileHorizontal), actionTileHorizontal);
addItem(_("Tile _Vertically"), -2,
KEY_NAME(gKeySysTileVertical), actionTileVertical);
}

YMenu* YWMApp::getWindowMenu() {
if (windowMenu)
return windowMenu;
Expand Down Expand Up @@ -593,6 +621,9 @@ YMenu* YWMApp::getWindowMenu() {
if (strchr(winMenuItems, 'y'))
windowMenu->addSubmenu(_("La_yer"), -2, layerMenu);

if (strchr(winMenuItems, 'y') && strchr(winMenuItems, 't'))
windowMenu->addSubmenu(_("Tile"), -2, tileMenu);

if (strchr(winMenuItems, 't') && workspaceCount > 1) {
windowMenu->addSeparator();
windowMenu->addSubmenu(_("Move _To"), -2, moveMenu);
Expand Down Expand Up @@ -1360,6 +1391,7 @@ YWMApp::~YWMApp() {
}
layerMenu = null;
moveMenu = null;
tileMenu = null;

keyProgs.clear();
workspaces.reset();
Expand Down
26 changes: 14 additions & 12 deletions src/wmapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,35 @@ class SharedWindowList : public WindowListMenu {
extern lazily<SharedWindowList> windowListMenu;
#endif

class LogoutMenu : public YMenu {
class SharedMenu : public YMenu {
public:
SharedMenu() { setShared(true); }
};

class LogoutMenu : public SharedMenu {
public:
LogoutMenu() {
setShared(true);
}
void updatePopup();
};
extern lazy<LogoutMenu> logoutMenu;

class LayerMenu : public YMenu {
class LayerMenu : public SharedMenu {
public:
LayerMenu() {
setShared(true);
}
void updatePopup();
};
extern lazy<LayerMenu> layerMenu;

class MoveMenu : public YMenu {
class MoveMenu : public SharedMenu {
public:
MoveMenu() {
setShared(true);
}
void updatePopup();
};
extern lazy<MoveMenu> moveMenu;

class TileMenu : public SharedMenu {
public:
void updatePopup();
};
extern lazy<TileMenu> tileMenu;

class KProgram;
typedef YObjectArray<KProgram> KProgramArrayType;
typedef KProgramArrayType::IterType KProgramIterType;
Expand Down
82 changes: 82 additions & 0 deletions src/wmframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,17 @@ void YFrameWindow::actionPerformed(YAction action, unsigned int modifiers) {
case actionToggleTray:
wmToggleTray();
break;
case actionTileLeft:
case actionTileRight:
case actionTileTop:
case actionTileBottom:
case actionTileTopLeft:
case actionTileTopRight:
case actionTileBottomLeft:
case actionTileBottomRight:
case actionTileCenter:
wmTile(action);
break;
case actionLayerDesktop:
case actionLayerOne:
case actionLayerBelow:
Expand Down Expand Up @@ -1136,6 +1147,77 @@ void YFrameWindow::actionPerformed(YAction action, unsigned int modifiers) {
}
}

void YFrameWindow::wmTile(YAction action) {
if (canMove() == false || visibleNow() == false) {
return;
}
if (hasState(WinStateMaximizedBoth | WinStateRollup)) {
if (notState(WinStateUnmapped | WinStateFullscreen)) {
setState(WinStateMaximizedBoth | WinStateRollup, None);
}
}
if (notState(WinStateUnmapped | WinStateFullscreen)) {
bool size = canSize();
int mx, my, Mx, My;
manager->getWorkArea(this, &mx, &my, &Mx, &My);
int x = this->x(), y = this->y();
int w = int(this->width()), h = int(this->height());
switch (action.ident()) {
case actionTileLeft:
if (size)
w = (Mx - mx) / 2, h = (My - my);
x = mx, y = my;
break;
case actionTileRight:
if (size)
w = (Mx - mx) / 2, h = (My - my);
x = (Mx - mx) / 2, y = my;
break;
case actionTileTop:
if (size)
w = (Mx - mx), h = (My - my) / 2;
x = mx, y = my;
break;
case actionTileBottom:
if (size)
w = (Mx - mx), h = (My - my) / 2;
x = mx, y = (My - my) / 2;
break;
case actionTileTopLeft:
if (size)
w = (Mx - mx) / 2, h = (My - my) / 2;
x = mx, y = my;
break;
case actionTileTopRight:
if (size)
w = (Mx - mx) / 2, h = (My - my) / 2;
x = (Mx - mx) / 2, y = my;
break;
case actionTileBottomLeft:
if (size)
w = (Mx - mx) / 2, h = (My - my) / 2;
x = mx, y = (My - my) / 2;
break;
case actionTileBottomRight:
if (size)
w = (Mx - mx) / 2, h = (My - my) / 2;
x = (Mx - mx) / 2, y = (My - my) / 2;
break;
case actionTileCenter:
if (size)
w = (Mx - mx) / 2, h = (My - my) / 2;
x = (mx + Mx - w) / 2, y = (my + My - h) / 2;
break;
default: return;
}
if (size) {
setNormalGeometryOuter(x, y, w, h);
} else {
setNormalPositionOuter(x, y);
}
}
}

void YFrameWindow::wmSetLayer(int layer) {
int previous = fWinState;
setRequestedLayer(layer);
Expand Down
1 change: 1 addition & 0 deletions src/wmframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class YFrameWindow:
void wmOccupyWorkspace(int workspace);
void wmSetLayer(int layer);
void wmSetTrayOption(int option);
void wmTile(YAction action);
void wmToggleTray();
#if DO_NOT_COVER_OLD
void wmToggleDoNotCover();
Expand Down
3 changes: 2 additions & 1 deletion src/wmwinlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ void WindowListBox::enableCommands(YMenu *popup) {
}
}
if (selected == false) {
moveMenu->disableCommand(actionNull);
popup->disableCommand(actionNull);
}
else {
moveMenu->setActionListener(this);
tileMenu->setActionListener(this);
layerMenu->setActionListener(this);
}
}
Expand Down Expand Up @@ -384,6 +384,7 @@ WindowListPopup::WindowListPopup() {
addItem(_("_Raise"), -2, KEY_NAME(gKeyWinRaise), actionRaise);
addItem(_("_Lower"), -2, KEY_NAME(gKeyWinLower), actionLower);
addSubmenu(_("La_yer"), -2, layerMenu);
addSubmenu(_("Tile"), -2, tileMenu);
addSeparator();
addSubmenu(_("Move _To"), -2, moveMenu);
addItem(_("Occupy _All"), -2, KEY_NAME(gKeyWinOccupyAll), actionOccupyAllOrCurrent);
Expand Down

0 comments on commit a061b0c

Please sign in to comment.