From: Stefan Bund Date: Mon, 12 Mar 2012 00:32:41 +0000 (+0100) Subject: add move-to-screen shortcuts X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;p=kwingrid.git add move-to-screen shortcuts --- diff --git a/kwingrid.cc b/kwingrid.cc index 1eb2bf7..64bbd2c 100644 --- a/kwingrid.cc +++ b/kwingrid.cc @@ -149,6 +149,33 @@ void KWinGrid::resizeRelative(int __xdiff, int __ydiff) } } +void KWinGrid::toScreen(int screen) +{ + initGeometry(); + if (activeWindow_) { + int xSize = (outer_.width()+hsize_/2)/hsize_; + if (xSize<1) xSize = 1; + if (xSize>hsplit_) xSize = hsplit_; + + int ySize = (outer_.height()+vsize_/2)/vsize_; + if (ySize<1) ySize = 1; + if (ySize>vsplit_) ySize = vsplit_; + + int xSlot = (outer_.left()-region_.left()+hsize_/2)/hsize_; + if (xSlot<0) xSlot = 0; + if (xSlot>=hsplit_) xSlot = hsplit_-1; + + int ySlot = (outer_.top()-region_.top()+vsize_/2)/vsize_; + if (ySlot<0) ySlot = 0; + if (ySlot>=vsplit_) ySlot = vsplit_-1; + + initGeometry(screen); + QRect newGeometry = doMoveResize(xSlot,ySlot,xSize,ySize); + updateGeometry(newGeometry); + applyGeometry(); + } +} + QRect KWinGrid::doMoveResize(int __xslot, int __yslot, int __xsize, int __ysize) { @@ -328,143 +355,61 @@ void KWinGrid::resizeSlot(int nx, int ny, int szx, int szy) // slots -void KWinGrid::move_TL() -{ - moveSlot(2, 2, 0, 0); -} - -void KWinGrid::move_TR() -{ - moveSlot(2, 2, 1, 0); -} - -void KWinGrid::move_BL() -{ - moveSlot(2, 2, 0, 1); -} - -void KWinGrid::move_BR() -{ - moveSlot(2, 2, 1, 1); -} - -void KWinGrid::resize_Q() -{ - resizeSlot(2, 2, 0, 0); -} - -void KWinGrid::resize_H() -{ - resizeSlot(2, 2, 1, 0); -} - -void KWinGrid::resize_V() -{ - resizeSlot(2, 2, 0, 1); -} - -void KWinGrid::resize_F() -{ - resizeSlot(2, 2, 1, 1); -} - -void KWinGrid::move_00() -{ - moveSlot(3, 2, 0, 0); -} - -void KWinGrid::move_10() -{ - moveSlot(3, 2, 1, 0); -} - -void KWinGrid::move_20() -{ - moveSlot(3, 2, 2, 0); -} - -void KWinGrid::move_01() -{ - moveSlot(3, 2, 0, 1); -} - -void KWinGrid::move_11() -{ - moveSlot(3, 2, 1, 1); -} - -void KWinGrid::move_21() -{ - moveSlot(3, 2, 2, 1); -} - -void KWinGrid::resize_00() -{ - resizeSlot(3, 2, 0, 0); -} - -void KWinGrid::resize_10() -{ - resizeSlot(3, 2, 1, 0); -} - -void KWinGrid::resize_20() -{ - resizeSlot(3, 2, 2, 0); -} - -void KWinGrid::resize_01() -{ - resizeSlot(3, 2, 0, 1); -} - -void KWinGrid::resize_11() -{ - resizeSlot(3, 2, 1, 1); -} - -void KWinGrid::resize_21() -{ - resizeSlot(3, 2, 2, 1); -} - -void KWinGrid::move_L() -{ - moveRelative(-1,0); -} - -void KWinGrid::move_R() -{ - moveRelative(1,0); -} - -void KWinGrid::move_U() -{ - moveRelative(0,-1); -} - -void KWinGrid::move_D() -{ - moveRelative(0,1); -} - -void KWinGrid::resize_IH() -{ - resizeRelative(1,0); -} - -void KWinGrid::resize_DH() -{ - resizeRelative(-1,0); -} - -void KWinGrid::resize_IV() -{ - resizeRelative(0,1); -} - -void KWinGrid::resize_DV() -{ - resizeRelative(0,-1); -} - +void KWinGrid::move_TL() { moveSlot(2, 2, 0, 0); } +void KWinGrid::move_TR() { moveSlot(2, 2, 1, 0); } +void KWinGrid::move_BL() { moveSlot(2, 2, 0, 1); } +void KWinGrid::move_BR() { moveSlot(2, 2, 1, 1); } +void KWinGrid::resize_Q() { resizeSlot(2, 2, 0, 0); } +void KWinGrid::resize_H() { resizeSlot(2, 2, 1, 0); } +void KWinGrid::resize_V() { resizeSlot(2, 2, 0, 1); } +void KWinGrid::resize_F() { resizeSlot(2, 2, 1, 1); } + +void KWinGrid::move32_00() { moveSlot(3, 2, 0, 0); } +void KWinGrid::move32_10() { moveSlot(3, 2, 1, 0); } +void KWinGrid::move32_20() { moveSlot(3, 2, 2, 0); } +void KWinGrid::move32_01() { moveSlot(3, 2, 0, 1); } +void KWinGrid::move32_11() { moveSlot(3, 2, 1, 1); } +void KWinGrid::move32_21() { moveSlot(3, 2, 2, 1); } +void KWinGrid::resize32_00() { resizeSlot(3, 2, 0, 0); } +void KWinGrid::resize32_10() { resizeSlot(3, 2, 1, 0); } +void KWinGrid::resize32_20() { resizeSlot(3, 2, 2, 0); } +void KWinGrid::resize32_01() { resizeSlot(3, 2, 0, 1); } +void KWinGrid::resize32_11() { resizeSlot(3, 2, 1, 1); } +void KWinGrid::resize32_21() { resizeSlot(3, 2, 2, 1); } + +void KWinGrid::move43_00() { moveSlot(4, 3, 0, 0); } +void KWinGrid::move43_10() { moveSlot(4, 3, 1, 0); } +void KWinGrid::move43_20() { moveSlot(4, 3, 2, 0); } +void KWinGrid::move43_30() { moveSlot(4, 3, 3, 0); } +void KWinGrid::move43_01() { moveSlot(4, 3, 0, 1); } +void KWinGrid::move43_11() { moveSlot(4, 3, 1, 1); } +void KWinGrid::move43_21() { moveSlot(4, 3, 2, 1); } +void KWinGrid::move43_31() { moveSlot(4, 3, 3, 1); } +void KWinGrid::move43_02() { moveSlot(4, 3, 0, 2); } +void KWinGrid::move43_12() { moveSlot(4, 3, 1, 2); } +void KWinGrid::move43_22() { moveSlot(4, 3, 2, 2); } +void KWinGrid::move43_32() { moveSlot(4, 3, 3, 2); } +void KWinGrid::resize43_00() { resizeSlot(4, 3, 0, 0); } +void KWinGrid::resize43_10() { resizeSlot(4, 3, 1, 0); } +void KWinGrid::resize43_20() { resizeSlot(4, 3, 2, 0); } +void KWinGrid::resize43_30() { resizeSlot(4, 3, 3, 0); } +void KWinGrid::resize43_01() { resizeSlot(4, 3, 0, 1); } +void KWinGrid::resize43_11() { resizeSlot(4, 3, 1, 1); } +void KWinGrid::resize43_21() { resizeSlot(4, 3, 2, 1); } +void KWinGrid::resize43_31() { resizeSlot(4, 3, 3, 1); } +void KWinGrid::resize43_02() { resizeSlot(4, 3, 0, 2); } +void KWinGrid::resize43_12() { resizeSlot(4, 3, 1, 2); } +void KWinGrid::resize43_22() { resizeSlot(4, 3, 2, 2); } +void KWinGrid::resize43_32() { resizeSlot(4, 3, 3, 2); } + +void KWinGrid::move_L() { moveRelative(-1,0); } +void KWinGrid::move_R() { moveRelative(1,0); } +void KWinGrid::move_U() { moveRelative(0,-1); } +void KWinGrid::move_D() { moveRelative(0,1); } +void KWinGrid::resize_IH() { resizeRelative(1,0); } +void KWinGrid::resize_DH() { resizeRelative(-1,0); } +void KWinGrid::resize_IV() { resizeRelative(0,1); } +void KWinGrid::resize_DV() { resizeRelative(0,-1); } + +void KWinGrid::move_Screen0() { toScreen(0); } +void KWinGrid::move_Screen1() { toScreen(1); } diff --git a/kwingrid.h b/kwingrid.h index 06afbd6..8551de4 100644 --- a/kwingrid.h +++ b/kwingrid.h @@ -26,6 +26,7 @@ public: int __xsize, int __ysize); virtual void moveRelative(int __xdiff, int __ydiff); virtual void resizeRelative(int __xdiff, int __ydiff); + virtual void toScreen(int screen); virtual void toDesk(int __desk); virtual void quit(); @@ -43,19 +44,43 @@ public slots: void resize_V(); void resize_F(); - void move_00(); - void move_10(); - void move_20(); - void move_01(); - void move_11(); - void move_21(); - - void resize_00(); - void resize_10(); - void resize_20(); - void resize_01(); - void resize_11(); - void resize_21(); + void move32_00(); + void move32_10(); + void move32_20(); + void move32_01(); + void move32_11(); + void move32_21(); + void resize32_00(); + void resize32_10(); + void resize32_20(); + void resize32_01(); + void resize32_11(); + void resize32_21(); + + void move43_00(); + void move43_10(); + void move43_20(); + void move43_30(); + void move43_01(); + void move43_11(); + void move43_21(); + void move43_31(); + void move43_02(); + void move43_12(); + void move43_22(); + void move43_32(); + void resize43_00(); + void resize43_10(); + void resize43_20(); + void resize43_30(); + void resize43_01(); + void resize43_11(); + void resize43_21(); + void resize43_31(); + void resize43_02(); + void resize43_12(); + void resize43_22(); + void resize43_32(); void move_L(); void move_R(); @@ -67,6 +92,9 @@ public slots: void resize_IV(); void resize_DV(); + void move_Screen0(); + void move_Screen1(); + public slots: void activeWindowChanged(WId id); diff --git a/main.cc b/main.cc index cca0894..51e4353 100644 --- a/main.cc +++ b/main.cc @@ -118,14 +118,40 @@ int main(int argc, char **argv) ACTION("bottom-left", K, move_BL); ACTION("bottom-right", L, move_BR); - ACTION("top-left (3x2 grid)", T, move_00); - ACTION("top-middle (3x2 grid)", Y, move_10); - ACTION("top-right (3x2 grid)", U, move_20); - ACTION("bottom-left (3x2 grid)", G, move_01); - ACTION("bottom-middle (3x2 grid)", H, move_11); - ACTION("bottom-right (3x2 grid)", J, move_21); + ACTION("top-left (3x2 grid)", T, move32_00); + ACTION("top-middle (3x2 grid)", Y, move32_10); + ACTION("top-right (3x2 grid)", U, move32_20); + ACTION("bottom-left (3x2 grid)", G, move32_01); + ACTION("bottom-middle (3x2 grid)", H, move32_11); + ACTION("bottom-right (3x2 grid)", J, move32_21); + + ACTION(" 0,0 (4x3 grid)", Q, move43_00); + ACTION(" 1,0 (4x3 grid)", W, move43_10); + ACTION(" 2,0 (4x3 grid)", E, move43_20); + ACTION(" 3,0 (4x3 grid)", R, move43_30); + ACTION(" 0,1 (4x3 grid)", A, move43_01); + ACTION(" 1,1 (4x3 grid)", S, move43_11); + ACTION(" 2,1 (4x3 grid)", D, move43_21); + ACTION(" 3,1 (4x3 grid)", F, move43_31); + ACTION(" 0,2 (4x3 grid)", Z, move43_02); + ACTION(" 1,2 (4x3 grid)", X, move43_12); + ACTION(" 2,2 (4x3 grid)", C, move43_22); + ACTION(" 3,2 (4x3 grid)", V, move43_32); #undef ACTION + +#define ACTION(pos, key, slot) \ + KAction * slot = new KAction(winGrid); \ + actions->addAction("Move to Screen " pos, slot); \ + slot->setHelpText("Move to Screen " pos); \ + slot->setGlobalShortcut(KShortcut( \ + Qt::ALT+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::SHIFT+Qt::Key_ ## key)); \ + QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot())) + + ACTION("0", B, move_Screen0); + ACTION("1", M, move_Screen1); +#undef ACTION + #define ACTION(size, key, slot) \ KAction * slot = new KAction(winGrid); \ actions->addAction("Resize " size, slot); \ @@ -140,14 +166,27 @@ int main(int argc, char **argv) ACTION("vertical", K, resize_V); ACTION("full", L, resize_F); - ACTION("top-left (3x2 grid)", T, resize_00); - ACTION("top-middle (3x2 grid)", Y, resize_10); - ACTION("top-right (3x2 grid)", U, resize_20); - ACTION("bottom-left (3x2 grid)", G, resize_01); - ACTION("bottom-middle (3x2 grid)", H, resize_11); - ACTION("bottom-right (3x2 grid)", J, resize_21); - + ACTION("top-left (3x2 grid)", T, resize32_00); + ACTION("top-middle (3x2 grid)", Y, resize32_10); + ACTION("top-right (3x2 grid)", U, resize32_20); + ACTION("bottom-left (3x2 grid)", G, resize32_01); + ACTION("bottom-middle (3x2 grid)", H, resize32_11); + ACTION("bottom-right (3x2 grid)", J, resize32_21); + + ACTION(" 0,0 (4x3 grid)", Q, resize43_00); + ACTION(" 1,0 (4x3 grid)", W, resize43_10); + ACTION(" 2,0 (4x3 grid)", E, resize43_20); + ACTION(" 3,0 (4x3 grid)", R, resize43_30); + ACTION(" 0,1 (4x3 grid)", A, resize43_01); + ACTION(" 1,1 (4x3 grid)", S, resize43_11); + ACTION(" 2,1 (4x3 grid)", D, resize43_21); + ACTION(" 3,1 (4x3 grid)", F, resize43_31); + ACTION(" 0,2 (4x3 grid)", Z, resize43_02); + ACTION(" 1,2 (4x3 grid)", X, resize43_12); + ACTION(" 2,2 (4x3 grid)", C, resize43_22); + ACTION(" 3,2 (4x3 grid)", V, resize43_32); #undef ACTION + #define ACTION(dir, key, slot) \ KAction * slot = new KAction(winGrid); \ actions->addAction("Move " dir, slot); \ @@ -160,8 +199,8 @@ int main(int argc, char **argv) ACTION("right", Right, move_R); ACTION("up", Up, move_U); ACTION("down", Down, move_D); - #undef ACTION + #define ACTION(resize, key, slot) \ KAction * slot = new KAction(winGrid); \ actions->addAction(resize " size", slot); \ @@ -174,7 +213,6 @@ int main(int argc, char **argv) ACTION("Increase vertical", Down, resize_IV); ACTION("Decrease horizontal", Left, resize_DH); ACTION("Decrease vertical", Up, resize_DV); - #undef ACTION int ret = app->exec();