+++ /dev/null
-#include <kapplication.h>
-#include <dcopclient.h>
-#include <kwin.h>
-#include <Xlib.h>
-
-#include "kwingrid.h"
-#include "kwingrid.moc"
-
-KWinGrid::KWinGrid(int hgap__, int vgap__, int hsplit__, int vsplit__)
- : DCOPObject("grid"), hgap_(hgap__), vgap_(vgap__), hsplit_(hsplit__), vsplit_(vsplit__)
-{
- module_ = new KWinModule(KApplication::kApplication());
-}
-
-void KWinGrid::move(int __xslot, int __yslot)
-{
- moveResize(__xslot, __yslot, -1, -1);
-}
-
-void KWinGrid::resize(int __xsize, int __ysize)
-{
- moveResize(-1,-1,__xsize,__ysize);
-}
-
-void KWinGrid::toDesk(int __desk)
-{
- int w = module_->activeWindow();
- if (w)
- KWin::setOnDesktop(w,__desk);
-}
-
-void KWinGrid::moveResize(int __xslot, int __yslot,
- int __xsize, int __ysize)
-{
- initGeometry();
- if (activeWindow_) {
- QRect newGeometry = doMoveResize(__xslot,__yslot,__xsize,__ysize);
- updateGeometry(newGeometry);
- applyGeometry();
- }
-}
-
-void KWinGrid::moveRelative(int __xdiff, int __ydiff)
-{
- initGeometry();
- if (activeWindow_) {
- int xSlot = (outer_.left()-region_.left()+hsize_/2)/hsize_;
- int ySlot = (outer_.top()-region_.top()+vsize_/2)/vsize_;
- xSlot += __xdiff;
- ySlot += __ydiff;
- if (xSlot<0)
- xSlot = 0;
- else if (xSlot >= hsplit_)
- xSlot = hsplit_-1;
- if (ySlot<0)
- ySlot = 0;
- else if (ySlot >= vsplit_)
- ySlot = vsplit_-1;
- QRect newGeometry = doMoveResize(xSlot,ySlot,-1,-1);
- updateGeometry(newGeometry);
- applyGeometry();
- }
-}
-
-void KWinGrid::resizeRelative(int __xdiff, int __ydiff)
-{
- initGeometry();
- if (activeWindow_) {
- int xSize = (outer_.width()+hsize_/2)/hsize_;
- int ySize = (outer_.height()+vsize_/2)/vsize_;
- xSize += __xdiff;
- ySize += __ydiff;
- if (xSize<1)
- xSize = 1;
- if (xSize>hsplit_)
- xSize = hsplit_;
- if (ySize<1)
- ySize = 1;
- if (ySize>vsplit_)
- ySize = vsplit_;
- QRect newGeometry = doMoveResize(-1,-1,xSize,ySize);
- updateGeometry(newGeometry);
- applyGeometry();
- }
-}
-
-QRect KWinGrid::doMoveResize(int __xslot, int __yslot,
- int __xsize, int __ysize)
-{
- QRect newGeometry(outer_);
-
- if (__xsize != -1)
- newGeometry.setWidth(__xsize*hsize_-hgap_);
- if (__ysize != -1)
- newGeometry.setHeight(__ysize*vsize_-vgap_);
- QSize size = newGeometry.size();
- if (__xslot != -1) {
- QPoint p(newGeometry.topLeft());
- p.setX(region_.left()
- + __xslot*hsize_
- + hgap_/2);
- newGeometry.moveTopLeft(p);
- }
- if (__yslot != -1) {
- QPoint p(newGeometry.topLeft());
- p.setY(region_.top()
- + __yslot*vsize_
- + vgap_/2);
- newGeometry.moveTopLeft(p);
- }
-
- return newGeometry;
-}
-
-void KWinGrid::initGeometry()
-{
- activeWindow_ = module_->activeWindow();
- if (activeWindow_) {
- KWin::Info info(KWin::info(activeWindow_));
- inner_ = info.geometry;
- outer_ = info.frameGeometry;
- region_ = module_->workArea();
-
- hsize_ = (region_.width()-hgap_)/hsplit_;
- vsize_ = (region_.height()-vgap_)/vsplit_;
-
- int hdelta = region_.width()-hsize_*hsplit_;
- int vdelta = region_.height()-vsize_*vsplit_;
- QPoint topLeft(region_.topLeft());
- topLeft+=QPoint(hdelta/2,vdelta/2);
- region_.moveTopLeft(topLeft);
- region_.setSize(QSize(hsize_*hsplit_,vsize_*vsplit_));
- }
-}
-
-void KWinGrid::updateGeometry(QRect& __new)
-{
- QRect newInner(inner_);
- newInner.moveTopLeft(QPoint(__new.top()+(inner_.top()-outer_.top()),
- __new.left()+(inner_.left()-outer_.left())));
- newInner.setSize(QSize(__new.width()-(outer_.width()-inner_.width()),
- __new.height()-(outer_.height()-inner_.height())));
- inner_ = newInner;
- outer_ = __new;
-}
-
-void KWinGrid::applyGeometry()
-{
- XMoveResizeWindow(KApplication::kApplication()->getDisplay(),activeWindow_,
- outer_.x(),outer_.y(),
- inner_.width(),inner_.height());
- KWin::setActiveWindow(activeWindow_);
-}
-
-// slots
-
-void KWinGrid::move_TL()
-{
- move(0,0);
-}
-
-void KWinGrid::move_TR()
-{
- move(hsplit_/2,0);
-}
-
-void KWinGrid::move_BL()
-{
- move(0,vsplit_/2);
-}
-
-void KWinGrid::move_BR()
-{
- move(hsplit_/2,vsplit_/2);
-}
-
-
-void KWinGrid::resize_Q()
-{
- resize(vsplit_/2,hsplit_/2);
-}
-
-void KWinGrid::resize_H()
-{
- resize(vsplit_,hsplit_/2);
-}
-
-void KWinGrid::resize_V()
-{
- resize(vsplit_/2,hsplit_);
-}
-
-void KWinGrid::resize_F()
-{
- resize(vsplit_,hsplit_);
-}
-
-
-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);
-}
-
+++ /dev/null
-#include <stdlib.h>
-#include <kuniqueapplication.h>
-#include <klocale.h>
-#include <kcmdlineargs.h>
-#include <kaboutdata.h>
-#include <kdebug.h>
-#include <kglobalaccel.h>
-#include <qnamespace.h>
-
-#include "kwingrid.h"
-
-static KCmdLineOptions winGridOpts[] =
-{
- { "+hgap", I18N_NOOP("hgap"), 0 },
- { "+vgap", I18N_NOOP("vgap"), 0 },
- { "+hsplit", I18N_NOOP("hsplit"), 0 },
- { "+vsplit", I18N_NOOP("vsplit"), 0 },
- { 0,0,0 }
-};
-
-/* Die optimalen werte für hgap und vgap berechnen sich zu:
- *
- * gap = size % split + n * split
- *
- * für n = 0,1,2,... und size die Bildschirmgröße in der jeweiligen Richtung
- */
-
-int main(int argc, char **argv)
-{
- KAboutData * aboutdata = new KAboutData("kwingrid","KWinGrid","0.5",
- I18N_NOOP("Window Grid"),
- KAboutData::License_GPL,
- "(C) 1999,2000,2002, Stefan Bund",
- "", "http://home.t-online.de/home/Stefan.Bund/");
- aboutdata->addAuthor("Stefan Bund",I18N_NOOP("Developer"),"asbund@gmx.de",
- "http://home.t-online.de/home/Stefan.Bund");
-
- KCmdLineArgs::init(argc, argv, aboutdata);
- KCmdLineArgs::addCmdLineOptions(winGridOpts);
- KUniqueApplication::addCmdLineOptions();
-
- if (! KUniqueApplication::start()) {
- kdError() << "KWinGrid is already running!" << endl;
- return 0;
- }
-
- KApplication * app = new KUniqueApplication;
- KCmdLineArgs * args = KCmdLineArgs::parsedArgs();
-
- if (args->count()!=4) {
- kdError() << "Invalid arguments. Try --help\n";
- return 0;
- }
-
- int hgap = atoi(args->arg(0));
- int vgap = atoi(args->arg(1));
- int hsplit = atoi(args->arg(2));
- int vsplit = atoi(args->arg(3));
-
- args->clear();
-
- KWinGrid * winGrid = new KWinGrid(hgap,vgap,hsplit,vsplit);
-
- KGlobalAccel * accel = new KGlobalAccel(app);
-
- accel->insert("move_TL",
- I18N_NOOP("Move top-left"),
- I18N_NOOP("Move active window top-left"),
- Qt::ALT+Qt::SHIFT+Qt::Key_I, KKey::QtWIN+Qt::SHIFT+Qt::Key_I,
- winGrid, SLOT ( move_TL() ));
- accel->insert("move_TR",
- I18N_NOOP("Move top-right"),
- I18N_NOOP("Move active window top-right"),
- Qt::ALT+Qt::SHIFT+Qt::Key_O, KKey::QtWIN+Qt::SHIFT+Qt::Key_O,
- winGrid, SLOT ( move_TR() ));
- accel->insert("move_BL",
- I18N_NOOP("Move bottom-left"),
- I18N_NOOP("Move active window bottom-left"),
- Qt::ALT+Qt::SHIFT+Qt::Key_K, KKey::QtWIN+Qt::SHIFT+Qt::Key_K,
- winGrid, SLOT ( move_BL() ));
- accel->insert("move_BR",
- I18N_NOOP("Move bottom-right"),
- I18N_NOOP("Move active window bottom-right"),
- Qt::ALT+Qt::SHIFT+Qt::Key_L, KKey::QtWIN+Qt::SHIFT+Qt::Key_L,
- winGrid, SLOT ( move_BR() ));
-
- accel->insert("resize_Q",
- I18N_NOOP("Resize quarter"), I18N_NOOP("Resize quarter"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_I, KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_I,
- winGrid, SLOT ( resize_Q() ));
- accel->insert("resize_H",
- I18N_NOOP("Resize horizontal"), I18N_NOOP("Resize horizontal"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_O, KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_O,
- winGrid, SLOT ( resize_H() ));
- accel->insert("resize_V",
- I18N_NOOP("Resize vertical"), I18N_NOOP("Resize vertical"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_K, KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_K,
- winGrid, SLOT ( resize_V() ));
- accel->insert("resize_F",
- I18N_NOOP("Resize full"), I18N_NOOP("Resize full"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_L, KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_L,
- winGrid, SLOT ( resize_F() ));
-
- accel->insert("move_L",
- I18N_NOOP("Move left"), I18N_NOOP("Move left"),
- Qt::ALT+Qt::SHIFT+Qt::Key_Left, KKey::QtWIN+Qt::SHIFT+Qt::Key_Left,
- winGrid, SLOT ( move_L() ));
- accel->insert("move_R",
- I18N_NOOP("Move right"), I18N_NOOP("Move right"),
- Qt::ALT+Qt::SHIFT+Qt::Key_Right, KKey::QtWIN+Qt::SHIFT+Qt::Key_Right,
- winGrid, SLOT ( move_R() ));
- accel->insert("move_U",
- I18N_NOOP("Move up"), I18N_NOOP("Move up"),
- Qt::ALT+Qt::SHIFT+Qt::Key_Up, KKey::QtWIN+Qt::SHIFT+Qt::Key_Up,
- winGrid, SLOT ( move_U() ));
- accel->insert("move_D",
- I18N_NOOP("Move down"), I18N_NOOP("Move down"),
- Qt::ALT+Qt::SHIFT+Qt::Key_Down, KKey::QtWIN+Qt::SHIFT+Qt::Key_Down,
- winGrid, SLOT ( move_D() ));
-
- accel->insert("resize_IH",
- I18N_NOOP("Increase horizontal size"), I18N_NOOP("Increase horizontal size"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Right,KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_Right,
- winGrid, SLOT ( resize_IH() ));
- accel->insert("resize_IV",
- I18N_NOOP("Increase vertical size"), I18N_NOOP("Increase vertical size"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Down,KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_Down,
- winGrid, SLOT ( resize_IV() ));
- accel->insert("resize_DH",
- I18N_NOOP("Decrease horizontal size"), I18N_NOOP("Decrease horizontal size"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Left,KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_Left,
- winGrid, SLOT ( resize_DH() ));
- accel->insert("resize_DV",
- I18N_NOOP("Decrease vertical size"), I18N_NOOP("Decrease vertical size"),
- Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Up,KKey::QtWIN+Qt::CTRL+Qt::SHIFT+Qt::Key_Up,
- winGrid, SLOT ( resize_DV() ));
-
-
- accel->updateConnections();
-
-
- int ret = app->exec();
-
- delete app;
- return ret;
-}
-