From: Stefan Bund Date: Wed, 28 Dec 2011 19:20:33 +0000 (+0100) Subject: screen-thirds based shortcuts, xinerama aware strut overide, auto unmaximize X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=acc7921a5dbe98c5fb272952a3807a4e9a40561d;p=kwingrid.git screen-thirds based shortcuts, xinerama aware strut overide, auto unmaximize --- diff --git a/kwingrid.cc b/kwingrid.cc index 06a1580..1eb2bf7 100644 --- a/kwingrid.cc +++ b/kwingrid.cc @@ -11,11 +11,12 @@ #include "kwingrid.moc" KWinGrid::KWinGrid(int hgap__, int vgap__, int hsplit__, int vsplit__, int split__, - int ignorestruts__, int reserveNorth__, int reserveSouth__, - int reserveWest__, int reserveEast__) + int ignorestruts__, int reserveNorth__, int reserveSouth__, int reserveWest__, int reserveEast__, + int southstrut__, int strutscreen__) : split_(split__), ignorestruts_(ignorestruts__), reserveNorth_(reserveNorth__), reserveSouth_(reserveSouth__), reserveEast_(reserveEast__), reserveWest_(reserveWest__), - hgap_(hgap__), vgap_(vgap__), hsplit_(hsplit__), vsplit_(vsplit__) + hgap_(hgap__), vgap_(vgap__), hsplit_(hsplit__), vsplit_(vsplit__), + southstrut_(southstrut__), strutscreen_(strutscreen__) { connect(KWindowSystem::self(),SIGNAL(activeWindowChanged(WId)), this,SLOT(activeWindowChanged(WId))); @@ -73,7 +74,7 @@ void KWinGrid::activeWindowChanged(WId id) deltaMSecs += deltaDays * 1000*(60*60*24); - if (deltaMSecs <= 1000 && deltaMSecs > 0) + if (deltaMSecs <= 500 && deltaMSecs > 0) KWindowSystem::forceActiveWindow(activeWindow_); else activeWindow_ = 0; @@ -227,12 +228,16 @@ void KWinGrid::initGeometry(int __forceScreen) else screen_ = __forceScreen; region_ = QApplication::desktop()->screenGeometry(screen_); + // region_ = QApplication::desktop()->availableGeometry(screen_); numScreens_ = QApplication::desktop()->numScreens(); } - if (screen_ != ignorestruts_) { + if (screen_ != ignorestruts_ && ignorestruts_ != -1) { QRect wa = KWindowSystem::workArea(); region_ = region_ & wa; } + if (screen_ == strutscreen_ || strutscreen_ == -1) { + region_.setHeight(region_.height() - southstrut_); + } hsize_ = (region_.width()-hgap_)/hsplit_; vsize_ = (region_.height()-vgap_)/vsplit_; @@ -287,6 +292,7 @@ void KWinGrid::updateGeometry(QRect& __new) void KWinGrid::applyGeometry() { updateTimestamp(); + KWindowSystem::clearState(activeWindow_, NET::MaxVert | NET::MaxHoriz | NET::FullScreen); if (orig_.topLeft() == outer_.topLeft()) // If the position of the window did not change, // XMoveResizeWindow sometimes still moves the window a little @@ -308,47 +314,118 @@ void KWinGrid::applyGeometry() } } +void KWinGrid::moveSlot(int nx, int ny, int posx, int posy) +{ + move((hsplit_-reserveWest_-reserveEast_)/nx * posx + reserveWest_, + (vsplit_-reserveNorth_-reserveSouth_)/ny * posy + reserveNorth_); +} + +void KWinGrid::resizeSlot(int nx, int ny, int szx, int szy) +{ + resize((hsplit_-reserveWest_-reserveEast_)/nx * (szx+1), + (vsplit_-reserveNorth_-reserveSouth_)/ny * (szy+1)); +} + // slots void KWinGrid::move_TL() { - move(reserveWest_,reserveNorth_); + moveSlot(2, 2, 0, 0); } void KWinGrid::move_TR() { - move((hsplit_-reserveWest_-reserveEast_)/2+reserveWest_,reserveNorth_); + moveSlot(2, 2, 1, 0); } void KWinGrid::move_BL() { - move(reserveWest_,(vsplit_-reserveNorth_-reserveSouth_)/2+reserveNorth_); + moveSlot(2, 2, 0, 1); } void KWinGrid::move_BR() { - move((hsplit_-reserveWest_-reserveEast_)/2+reserveWest_, - (vsplit_-reserveNorth_-reserveSouth_)/2+reserveNorth_); + moveSlot(2, 2, 1, 1); } void KWinGrid::resize_Q() { - resize((hsplit_-reserveWest_-reserveEast_)/2,(vsplit_-reserveNorth_-reserveSouth_)/2); + resizeSlot(2, 2, 0, 0); } void KWinGrid::resize_H() { - resize((hsplit_-reserveWest_-reserveEast_),(vsplit_-reserveNorth_-reserveSouth_)/2); + resizeSlot(2, 2, 1, 0); } void KWinGrid::resize_V() { - resize((hsplit_-reserveWest_-reserveEast_)/2,vsplit_-reserveNorth_-reserveSouth_); + resizeSlot(2, 2, 0, 1); } void KWinGrid::resize_F() { - resize(hsplit_-reserveWest_-reserveEast_,vsplit_-reserveNorth_-reserveSouth_); + 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() @@ -390,3 +467,4 @@ void KWinGrid::resize_DV() { resizeRelative(0,-1); } + diff --git a/kwingrid.h b/kwingrid.h index f596adc..06afbd6 100644 --- a/kwingrid.h +++ b/kwingrid.h @@ -17,7 +17,8 @@ class KWinGrid : public QObject public: KWinGrid(int hgap__, int vgap__, int hsplit__, int vsplit__, int split__=0, int ignorestruts__=-1, - int reserveNorth__=0, int reserveSouth__=0, int reserveWest__=0, int reserveEast__=0); + int reserveNorth__=0, int reserveSouth__=0, int reserveWest__=0, int reserveEast__=0, + int southstrut__=0, int strutscreen__=-2); virtual void move(int __xslot, int __yslot); virtual void resize(int __xsize, int __ysize); @@ -42,6 +43,20 @@ 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 move_L(); void move_R(); void move_U(); @@ -61,6 +76,8 @@ private: void applyGeometry(); QRect doMoveResize(int __xslot, int __yslot, int __xsize, int __ysize); + void moveSlot(int nx, int ny, int posx, int posy); + void resizeSlot(int nx, int ny, int szx, int szy); void updateTimestamp(void); @@ -88,6 +105,9 @@ private: int hsplit_; int vsplit_; + int southstrut_; + int strutscreen_; + QDateTime timestamp_; }; diff --git a/main.cc b/main.cc index 2f944a2..cca0894 100644 --- a/main.cc +++ b/main.cc @@ -30,11 +30,13 @@ int main(int argc, char **argv) KCmdLineOptions winGridOpts; winGridOpts.add("split ", ki18n("split"), 0); - winGridOpts.add("ignorestruts ", ki18n("ignorestruts"), ""); + winGridOpts.add("ignorestruts ", ki18n("ignorestruts. -1 = all screens"), ""); winGridOpts.add("reserve-north ", ki18n("reserve north"), ""); winGridOpts.add("reserve-south ", ki18n("reserve south"), ""); winGridOpts.add("reserve-west ", ki18n("reserve west"), ""); winGridOpts.add("reserve-east ", ki18n("reserve east"), ""); + winGridOpts.add("southstrut ", ki18n("set south strut size"), ""); + winGridOpts.add("strutscreen ", ki18n("set screen to apply manual strut to. -1 = all screens"), ""); winGridOpts.add("+hgap", ki18n("hgap"), 0); winGridOpts.add("+vgap", ki18n("vgap"), 0); winGridOpts.add("+hsplit", ki18n("hsplit"), 0); @@ -58,7 +60,7 @@ int main(int argc, char **argv) } int split = 0; - int ignorestruts = -1; + int ignorestruts = -2; if (args->isSet("split")) split = args->getOption("split").toInt(); @@ -70,6 +72,13 @@ int main(int argc, char **argv) return 1; } + int southstrut (0); + int strutscreen (-2); + if (args->isSet("southstrut")) + southstrut = args->getOption("southstrut").toInt(); + if (args->isSet("strutscreen")) + strutscreen = args->getOption("strutscreen").toInt(); + int rn = 0; int rs = 0; int re = 0; @@ -92,125 +101,84 @@ int main(int argc, char **argv) args->clear(); KWinGrid * winGrid = new KWinGrid(hgap,vgap,hsplit,vsplit,split,ignorestruts, - rn, rs, rw, re); + rn, rs, rw, re, southstrut, strutscreen); KActionCollection * actions = new KActionCollection(winGrid); - KAction * move_TL = new KAction(winGrid); - actions->addAction("Move top-left", move_TL); - move_TL->setHelpText("Move active window top-left"); - move_TL->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_I, Qt::META+Qt::SHIFT+Qt::Key_I)); - QObject::connect(move_TL, SIGNAL(triggered(bool)), winGrid, SLOT(move_TL())); - - KAction * move_TR = new KAction(winGrid); - actions->addAction("Move top-right", move_TR); - move_TR->setHelpText("Move active window top-right"); - move_TR->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_O, Qt::META+Qt::SHIFT+Qt::Key_O)); - QObject::connect(move_TR, SIGNAL(triggered(bool)), winGrid, SLOT(move_TR())); - - KAction * move_BL = new KAction(winGrid); - actions->addAction("Move bottom-left", move_BL); - move_BL->setHelpText("Move active window bottom-left"); - move_BL->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_K, Qt::META+Qt::SHIFT+Qt::Key_K)); - QObject::connect(move_BL, SIGNAL(triggered(bool)), winGrid, SLOT(move_BL())); - - KAction * move_BR = new KAction(winGrid); - actions->addAction("Move bottom-right", move_BR); - move_BR->setHelpText("Move active window bottom-right"); - move_BR->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_L, Qt::META+Qt::SHIFT+Qt::Key_L)); - QObject::connect(move_BR, SIGNAL(triggered(bool)), winGrid, SLOT(move_BR())); - - KAction * resize_Q = new KAction(winGrid); - actions->addAction("Resize quarter", resize_Q); - resize_Q->setHelpText("Resize quarter"); - resize_Q->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_I, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_I)); - QObject::connect(resize_Q, SIGNAL(triggered(bool)), winGrid, SLOT(resize_Q())); - - KAction * resize_H = new KAction(winGrid); - actions->addAction("Resize horizontal", resize_H); - resize_H->setHelpText("Resize horizontal"); - resize_H->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_O, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_O)); - QObject::connect(resize_H, SIGNAL(triggered(bool)), winGrid, SLOT(resize_H())); - - KAction * resize_V = new KAction(winGrid); - actions->addAction("Resize vertical", resize_V); - resize_V->setHelpText("Resize vertical"); - resize_V->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_K, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_K)); - QObject::connect(resize_V, SIGNAL(triggered(bool)), winGrid, SLOT(resize_V())); - - KAction * resize_F = new KAction(winGrid); - actions->addAction("Resize full", resize_F); - resize_F->setHelpText("Resize full"); - resize_F->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_L, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_L)); - QObject::connect(resize_F, SIGNAL(triggered(bool)), winGrid, SLOT(resize_F())); - - KAction * move_L = new KAction(winGrid); - actions->addAction("Move left", move_L); - move_L->setHelpText("Move left"); - move_L->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_Left, Qt::META+Qt::SHIFT+Qt::Key_Left)); - QObject::connect(move_L, SIGNAL(triggered(bool)), winGrid, SLOT(move_L())); - - KAction * move_R = new KAction(winGrid); - actions->addAction("Move right", move_R); - move_R->setHelpText("Move right"); - move_R->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_Right, Qt::META+Qt::SHIFT+Qt::Key_Right)); - QObject::connect(move_R, SIGNAL(triggered(bool)), winGrid, SLOT(move_R())); - - KAction * move_U = new KAction(winGrid); - actions->addAction("Move up", move_U); - move_U->setHelpText("Move up"); - move_U->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_Up, Qt::META+Qt::SHIFT+Qt::Key_Up)); - QObject::connect(move_U, SIGNAL(triggered(bool)), winGrid, SLOT(move_U())); - - KAction * move_D = new KAction(winGrid); - actions->addAction("Move down", move_D); - move_D->setHelpText("Move down"); - move_D->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::SHIFT+Qt::Key_Down, Qt::META+Qt::SHIFT+Qt::Key_Down)); - QObject::connect(move_D, SIGNAL(triggered(bool)), winGrid, SLOT(move_D())); - - KAction * resize_IH = new KAction(winGrid); - actions->addAction("Increase horizontal size", resize_IH); - resize_IH->setHelpText("Increase horizontal size"); - resize_IH->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Right,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Right)); - QObject::connect(resize_IH, SIGNAL(triggered(bool)), winGrid, SLOT(resize_IH())); - - KAction * resize_IV = new KAction(winGrid); - actions->addAction("Increase vertical size", resize_IV); - resize_IV->setHelpText("Increase vertical size"); - resize_IV->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Down,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Down)); - QObject::connect(resize_IV, SIGNAL(triggered(bool)), winGrid, SLOT(resize_IV())); - - KAction * resize_DH = new KAction(winGrid); - actions->addAction("Decrease horizontal size", resize_DH); - resize_DH->setHelpText("Decrease horizontal size"); - resize_DH->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Left,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Left)); - QObject::connect(resize_DH, SIGNAL(triggered(bool)), winGrid, SLOT(resize_DH())); - - KAction * resize_DV = new KAction(winGrid); - actions->addAction("Decrease vertical size", resize_DV); - resize_DV->setHelpText("Decrease vertical size"); - resize_DV->setGlobalShortcut(KShortcut( - Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Up,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Up)); - QObject::connect(resize_DV, SIGNAL(triggered(bool)), winGrid, SLOT(resize_DV())); +#define ACTION(pos, key, slot) \ + KAction * slot = new KAction(winGrid); \ + actions->addAction("Move " pos, slot); \ + slot->setHelpText("Move active window" 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("top-left", I, move_TL); + ACTION("top-right", O, move_TR); + 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); + +#undef ACTION +#define ACTION(size, key, slot) \ + KAction * slot = new KAction(winGrid); \ + actions->addAction("Resize " size, slot); \ + slot->setHelpText("Resize " size); \ + slot->setGlobalShortcut(KShortcut( \ + Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \ + QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot())); + + ACTION("quarter", I, resize_Q); + + ACTION("horizontal", O, resize_H); + 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); + +#undef ACTION +#define ACTION(dir, key, slot) \ + KAction * slot = new KAction(winGrid); \ + actions->addAction("Move " dir, slot); \ + slot->setHelpText("Move " dir); \ + 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("left", Left, move_L); + 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); \ + slot->setHelpText(resize " size"); \ + slot->setGlobalShortcut(KShortcut( \ + Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \ + QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot())); + + ACTION("Increase horizontal", Right, resize_IH); + ACTION("Increase vertical", Down, resize_IV); + ACTION("Decrease horizontal", Left, resize_DH); + ACTION("Decrease vertical", Up, resize_DV); + +#undef ACTION int ret = app->exec(); delete app; return ret; } -