Skip to content

Commit

Permalink
Add key bindings for single window tiling operations for issues #335, i…
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Jul 26, 2022
1 parent 79ee5df commit 80a4a85
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 62 deletions.
36 changes: 36 additions & 0 deletions man/icewm.pod
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,42 @@ Moves the active window to the middle left of the screen.

Moves the active window to the center of the screen.

=item B<KeyWinTileLeft>=""

Let the active window occupy the left half of the screen.

=item B<KeyWinTileRight>=""

Let the active window occupy the right half of the screen.

=item B<KeyWinTileTop>=""

Let the active window occupy the top half of the screen.

=item B<KeyWinTileBottom>=""

Let the active window occupy the bottom half of the screen.

=item B<KeyWinTileTopLeft>=""

Let the active window occupy the top left quarter of the screen.

=item B<KeyWinTileTopRight>=""

Let the active window occupy the top right quarter of the screen.

=item B<KeyWinTileBottomLeft>=""

Let the active window occupy the bottom left quarter of the screen.

=item B<KeyWinTileBottomRight>=""

Let the active window occupy the bottom right quarter of the screen.

=item B<KeyWinTileCenter>=""

Let the active window occupy the center quarter of the screen.

=item B<KeyWinSmartPlace>=C<Ctrl+Alt+Shift+KP_5>

Smart place the active window.
Expand Down
36 changes: 27 additions & 9 deletions src/bindkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@
#define defgKeyWinFullscreen XK_F11, kfAlt, "Alt+F11"
#define defgKeyWinHide XK_F12, kfAlt+kfShift, "Alt+Shift+F12"
#define defgKeyWinRollup XK_F12, kfAlt, "Alt+F12"
#define defgKeyWinArrangeN XK_KP_Up, kfCtrl+kfAlt, "Ctrl+Alt+KP_8"
#define defgKeyWinArrangeNE XK_KP_Prior, kfCtrl+kfAlt, "Ctrl+Alt+KP_9"
#define defgKeyWinArrangeE XK_KP_Right, kfCtrl+kfAlt, "Ctrl+Alt+KP_6"
#define defgKeyWinArrangeSE XK_KP_Next, kfCtrl+kfAlt, "Ctrl+Alt+KP_3"
#define defgKeyWinArrangeS XK_KP_Down, kfCtrl+kfAlt, "Ctrl+Alt+KP_2"
#define defgKeyWinArrangeSW XK_KP_End, kfCtrl+kfAlt, "Ctrl+Alt+KP_1"
#define defgKeyWinArrangeW XK_KP_Left, kfCtrl+kfAlt, "Ctrl+Alt+KP_4"
#define defgKeyWinArrangeNW XK_KP_Home, kfCtrl+kfAlt, "Ctrl+Alt+KP_7"
#define defgKeyWinArrangeC XK_KP_Begin, kfCtrl+kfAlt, "Ctrl+Alt+KP_5"
#define defgKeyWinArrangeN XK_KP_Up, kfCtrl+kfAlt, "Ctrl+Alt+KP_Up"
#define defgKeyWinArrangeNE XK_KP_Prior, kfCtrl+kfAlt, "Ctrl+Alt+KP_Prior"
#define defgKeyWinArrangeE XK_KP_Right, kfCtrl+kfAlt, "Ctrl+Alt+KP_Right"
#define defgKeyWinArrangeSE XK_KP_Next, kfCtrl+kfAlt, "Ctrl+Alt+KP_Next"
#define defgKeyWinArrangeS XK_KP_Down, kfCtrl+kfAlt, "Ctrl+Alt+KP_Down"
#define defgKeyWinArrangeSW XK_KP_End, kfCtrl+kfAlt, "Ctrl+Alt+KP_End"
#define defgKeyWinArrangeW XK_KP_Left, kfCtrl+kfAlt, "Ctrl+Alt+KP_Left"
#define defgKeyWinArrangeNW XK_KP_Home, kfCtrl+kfAlt, "Ctrl+Alt+KP_Home"
#define defgKeyWinArrangeC XK_KP_Begin, kfCtrl+kfAlt, "Ctrl+Alt+KP_Begin"
#define defgKeyWinTileLeft 0, 0, ""
#define defgKeyWinTileRight 0, 0, ""
#define defgKeyWinTileTop 0, 0, ""
#define defgKeyWinTileBottom 0, 0, ""
#define defgKeyWinTileTopLeft 0, 0, ""
#define defgKeyWinTileTopRight 0, 0, ""
#define defgKeyWinTileBottomLeft 0, 0, ""
#define defgKeyWinTileBottomRight 0, 0, ""
#define defgKeyWinTileCenter 0, 0, ""
#define defgKeyWinSmartPlace XK_KP_Begin, kfCtrl+kfAlt+kfShift, "Ctrl+Alt+Shift+KP_5"
#define defgKeySysSwitchNext XK_Tab, kfAlt, "Alt+Tab"
#define defgKeySysSwitchLast XK_Tab, kfAlt+kfShift, "Alt+Shift+Tab"
Expand Down Expand Up @@ -127,6 +136,15 @@ DEF_WMKEY(gKeyWinArrangeSW);
DEF_WMKEY(gKeyWinArrangeW);
DEF_WMKEY(gKeyWinArrangeNW);
DEF_WMKEY(gKeyWinArrangeC);
DEF_WMKEY(gKeyWinTileLeft);
DEF_WMKEY(gKeyWinTileRight);
DEF_WMKEY(gKeyWinTileTop);
DEF_WMKEY(gKeyWinTileBottom);
DEF_WMKEY(gKeyWinTileTopLeft);
DEF_WMKEY(gKeyWinTileTopRight);
DEF_WMKEY(gKeyWinTileBottomLeft);
DEF_WMKEY(gKeyWinTileBottomRight);
DEF_WMKEY(gKeyWinTileCenter);
DEF_WMKEY(gKeyWinSmartPlace);
DEF_WMKEY(gKeyWinMenu);
DEF_WMKEY(gKeySysSwitchNext);
Expand Down
9 changes: 9 additions & 0 deletions src/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ cfoption icewm_preferences[] = {
OKV("KeyWinArrangeW", gKeyWinArrangeW, "Moves the active window to the middle left of the screen."),
OKV("KeyWinArrangeNW", gKeyWinArrangeNW, "Moves the active window to the top left corner of the screen."),
OKV("KeyWinArrangeC", gKeyWinArrangeC, "Moves the active window to the top middle of the screen."),
OKV("KeyWinTileLeft", gKeyWinTileLeft, "Let the active window occupy the left half of the screen"),
OKV("KeyWinTileRight", gKeyWinTileRight, "Let the active window occupy the right half of the screen"),
OKV("KeyWinTileTop", gKeyWinTileTop, "Let the active window occupy the top half of the screen"),
OKV("KeyWinTileBottom", gKeyWinTileBottom, "Let the active window occupy the bottom half of the screen"),
OKV("KeyWinTileTopLeft", gKeyWinTileTopLeft, "Let the active window occupy the top left quarter of the screen"),
OKV("KeyWinTileTopRight", gKeyWinTileTopRight, "Let the active window occupy the top right quarter of the screen"),
OKV("KeyWinTileBottomLeft", gKeyWinTileBottomLeft, "Let the active window occupy the bottom left quarter of the screen"),
OKV("KeyWinTileBottomRight", gKeyWinTileBottomRight, "Let the active window occupy the bottom right quarter of the screen"),
OKV("KeyWinTileCenter", gKeyWinTileCenter, "Let the active window occupy the center quarter of the screen"),
OKV("KeyWinSmartPlace", gKeyWinSmartPlace, "Smart place the active window."),
OKV("KeySysSwitchNext", gKeySysSwitchNext, "Opens the QuickSwitch popup and/or moves the selector in the QuickSwitch popup"),
OKV("KeySysSwitchLast", gKeySysSwitchLast, "Works like KeySysSwitchNext but moving in the opposite direction."),
Expand Down
10 changes: 9 additions & 1 deletion src/genpref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void addBgImage(const char *, const char *, bool) {}
static const char workspaceNames[] =
"\" 1 \", \" 2 \", \" 3 \", \" 4 \"";
static bool sorted, internal, themable;
static const char* pattern;

static int count(cfoption* options) {
for (int i = 0; ; ++i)
Expand Down Expand Up @@ -116,6 +117,9 @@ static void ppod(cfoption *options) {
sort(options);

for (unsigned int i = 0; options[i].type != cfoption::CF_NONE; i++) {
if (pattern && !strstr(options[i].name, pattern))
continue;

switch (options[i].type) {
case cfoption::CF_BOOL:
printf("=item B<%s>=%d\n",
Expand Down Expand Up @@ -230,8 +234,9 @@ static void podpref()
static const char* help_text()
{
return
" -e string Print only preferences containing 'string'.\n"
" -n Print only non-themable preferences.\n"
" -o, --output=FILE Write preferences to FILE.\n"
" -o, --output=FILE Write all output to FILE.\n"
" -p Use perlpod output format.\n"
" -s Sort preferences by name.\n"
" -t Print only themable preferences.\n"
Expand All @@ -251,6 +256,9 @@ int main(int argc, char **argv)
if (GetArgument(value, "o", "output", arg, argv + argc)) {
output = value;
}
else if (GetShortArgument(value, "e", arg, argv + argc)) {
pattern = value;
}
else if (is_short_switch(*arg, "n")) {
internal = true;
}
Expand Down
18 changes: 18 additions & 0 deletions src/movesize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,24 @@ bool YFrameWindow::handleKey(const XKeyEvent &key) {
if (canMove()) wmArrange(waTop, waLeft);
} else if (IS_WMKEY(k, vm, gKeyWinArrangeC)) {
if (canMove()) wmArrange(waCenter, waCenter);
} else if (IS_WMKEY(k, vm, gKeyWinTileLeft)) {
wmTile(actionTileLeft);
} else if (IS_WMKEY(k, vm, gKeyWinTileRight)) {
wmTile(actionTileRight);
} else if (IS_WMKEY(k, vm, gKeyWinTileTop)) {
wmTile(actionTileTop);
} else if (IS_WMKEY(k, vm, gKeyWinTileBottom)) {
wmTile(actionTileBottom);
} else if (IS_WMKEY(k, vm, gKeyWinTileTopLeft)) {
wmTile(actionTileTopLeft);
} else if (IS_WMKEY(k, vm, gKeyWinTileTopRight)) {
wmTile(actionTileTopRight);
} else if (IS_WMKEY(k, vm, gKeyWinTileBottomLeft)) {
wmTile(actionTileBottomLeft);
} else if (IS_WMKEY(k, vm, gKeyWinTileBottomRight)) {
wmTile(actionTileBottomRight);
} else if (IS_WMKEY(k, vm, gKeyWinTileCenter)) {
wmTile(actionTileCenter);
} else if (IS_WMKEY(k, vm, gKeyWinSmartPlace)) {
if (canMove()) {
int newX = x();
Expand Down
26 changes: 11 additions & 15 deletions src/wmapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,21 @@ void TileMenu::updatePopup() {
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");
addItem(_("Left Half"), -2, gKeyWinTileLeft.name, actionTileLeft, "tileleft");
addItem(_("Right Half"), -2, gKeyWinTileRight.name, actionTileRight, "tileright");
addItem(_("Top Half"), -2, gKeyWinTileTop.name, actionTileTop, "tiletop");
addItem(_("Bottom Half"), -2, gKeyWinTileBottom.name, actionTileBottom, "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");
addItem(_("Top Left"), -2, gKeyWinTileTopLeft.name, actionTileTopLeft, "tiletopleft");
addItem(_("Top Right"), -2, gKeyWinTileTopRight.name, actionTileTopRight, "tiletopright");
addItem(_("Bottom Left"), -2, gKeyWinTileBottomLeft.name, actionTileBottomLeft, "tilebottomleft");
addItem(_("Bottom Right"), -2, gKeyWinTileBottomRight.name, actionTileBottomRight, "tilebottomright");
addItem(_("Center"), -2, gKeyWinTileCenter.name, actionTileCenter, "tilecenter");
addSeparator();
addItem(_("T_ile Horizontally"), -2,
KEY_NAME(gKeySysTileHorizontal), actionTileHorizontal);
gKeySysTileHorizontal.name, actionTileHorizontal);
addItem(_("Tile _Vertically"), -2,
KEY_NAME(gKeySysTileVertical), actionTileVertical);
gKeySysTileVertical.name, actionTileVertical);
}

YMenu* YWMApp::getWindowMenu() {
Expand Down
9 changes: 9 additions & 0 deletions src/wmframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ void YFrameWindow::grabKeys() {
GRAB_WMKEY(gKeyWinArrangeW);
GRAB_WMKEY(gKeyWinArrangeNW);
GRAB_WMKEY(gKeyWinArrangeC);
GRAB_WMKEY(gKeyWinTileLeft);
GRAB_WMKEY(gKeyWinTileRight);
GRAB_WMKEY(gKeyWinTileTop);
GRAB_WMKEY(gKeyWinTileBottom);
GRAB_WMKEY(gKeyWinTileTopLeft);
GRAB_WMKEY(gKeyWinTileTopRight);
GRAB_WMKEY(gKeyWinTileBottomLeft);
GRAB_WMKEY(gKeyWinTileBottomRight);
GRAB_WMKEY(gKeyWinTileCenter);
GRAB_WMKEY(gKeyWinSmartPlace);

container()->regrabMouse();
Expand Down
78 changes: 41 additions & 37 deletions src/ywindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1673,50 +1673,54 @@ YDesktop::~YDesktop() {
desktop = nullptr;
}

void YWindow::grabVKey(int key, unsigned int vm) {
unsigned m = 0;

if (vm & kfShift)
m |= ShiftMask;
if (vm & kfCtrl)
m |= ControlMask;
if (vm & kfAlt)
m |= xapp->AltMask;
if (vm & kfMeta)
m |= xapp->MetaMask;
if (vm & kfSuper)
m |= xapp->SuperMask;
if (vm & kfHyper)
m |= xapp->HyperMask;
if (vm & kfAltGr)
m |= xapp->ModeSwitchMask;

MSG(("grabVKey %d %d %d", key, vm, m));
if (key != 0 && (vm == 0 || m != 0)) {
if ((!(vm & kfMeta) || xapp->MetaMask) &&
(!(vm & kfAlt) || xapp->AltMask) &&
(!(vm & kfSuper) || xapp->SuperMask) &&
(!(vm & kfHyper) || xapp->HyperMask) &&
(!(vm & kfAltGr) || xapp->ModeSwitchMask))
{
grabKey(key, m);
}
void YWindow::grabVKey(int key, unsigned vm) {
if (key) {
unsigned m = 0;

// !!! recheck this
if (((vm & (kfAlt | kfCtrl)) == (kfAlt | kfCtrl)) &&
modSuperIsCtrlAlt &&
xapp->WinMask)
{
m = xapp->WinMask;
if (vm) {
if (vm & kfShift)
m |= ShiftMask;
if (vm & kfCtrl)
m |= ControlMask;
if (vm & kfAlt)
m |= xapp->AltMask;
if (vm & kfMeta)
m |= xapp->MetaMask;
if (vm & kfSuper)
m |= xapp->SuperMask;
m |= xapp->SuperMask;
if (vm & kfHyper)
m |= xapp->HyperMask;
m |= xapp->HyperMask;
if (vm & kfAltGr)
m |= xapp->ModeSwitchMask;
grabKey(key, m);
}

MSG(("grabVKey %d %d %d", key, vm, m));
if (m || !vm) {
if ((!(vm & kfMeta) || xapp->MetaMask) &&
(!(vm & kfAlt) || xapp->AltMask) &&
(!(vm & kfSuper) || xapp->SuperMask) &&
(!(vm & kfHyper) || xapp->HyperMask) &&
(!(vm & kfAltGr) || xapp->ModeSwitchMask))
{
grabKey(key, m);
}

// !!! recheck this
if (((vm & (kfAlt | kfCtrl)) == (kfAlt | kfCtrl)) &&
modSuperIsCtrlAlt &&
xapp->WinMask)
{
m = xapp->WinMask;
if (vm & kfShift)
m |= ShiftMask;
if (vm & kfSuper)
m |= xapp->SuperMask;
if (vm & kfHyper)
m |= xapp->HyperMask;
if (vm & kfAltGr)
m |= xapp->ModeSwitchMask;
grabKey(key, m);
}
}
}
}
Expand Down

0 comments on commit 80a4a85

Please sign in to comment.