1 #include <kapplication.h>
2 #include <dcopclient.h>
7 #include "kwingrid.moc"
9 KWinGrid::KWinGrid(int hgap__, int vgap__, int hsplit__, int vsplit__)
10 : DCOPObject("grid"), hgap_(hgap__), vgap_(vgap__), hsplit_(hsplit__), vsplit_(vsplit__)
12 module_ = new KWinModule(KApplication::kApplication());
15 void KWinGrid::move(int __xslot, int __yslot)
17 moveResize(__xslot, __yslot, -1, -1);
20 void KWinGrid::resize(int __xsize, int __ysize)
22 moveResize(-1,-1,__xsize,__ysize);
25 void KWinGrid::toDesk(int __desk)
27 int w = module_->activeWindow();
29 KWin::setOnDesktop(w,__desk);
32 void KWinGrid::moveResize(int __xslot, int __yslot,
33 int __xsize, int __ysize)
37 QRect newGeometry = doMoveResize(__xslot,__yslot,__xsize,__ysize);
38 updateGeometry(newGeometry);
43 void KWinGrid::moveRelative(int __xdiff, int __ydiff)
47 int xSlot = (outer_.left()-region_.left()+hsize_/2)/hsize_;
48 int ySlot = (outer_.top()-region_.top()+vsize_/2)/vsize_;
53 else if (xSlot >= hsplit_)
57 else if (ySlot >= vsplit_)
59 QRect newGeometry = doMoveResize(xSlot,ySlot,-1,-1);
60 updateGeometry(newGeometry);
65 void KWinGrid::resizeRelative(int __xdiff, int __ydiff)
69 int xSize = (outer_.width()+hsize_/2)/hsize_;
70 int ySize = (outer_.height()+vsize_/2)/vsize_;
81 QRect newGeometry = doMoveResize(-1,-1,xSize,ySize);
82 updateGeometry(newGeometry);
87 QRect KWinGrid::doMoveResize(int __xslot, int __yslot,
88 int __xsize, int __ysize)
90 QRect newGeometry(outer_);
93 newGeometry.setWidth(__xsize*hsize_-hgap_);
95 newGeometry.setHeight(__ysize*vsize_-vgap_);
96 QSize size = newGeometry.size();
98 QPoint p(newGeometry.topLeft());
102 newGeometry.moveTopLeft(p);
105 QPoint p(newGeometry.topLeft());
109 newGeometry.moveTopLeft(p);
115 void KWinGrid::initGeometry()
117 activeWindow_ = module_->activeWindow();
119 KWin::Info info(KWin::info(activeWindow_));
120 inner_ = info.geometry;
121 outer_ = info.frameGeometry;
122 region_ = module_->workArea();
124 hsize_ = (region_.width()-hgap_)/hsplit_;
125 vsize_ = (region_.height()-vgap_)/vsplit_;
127 int hdelta = region_.width()-hsize_*hsplit_;
128 int vdelta = region_.height()-vsize_*vsplit_;
129 QPoint topLeft(region_.topLeft());
130 topLeft+=QPoint(hdelta/2,vdelta/2);
131 region_.moveTopLeft(topLeft);
132 region_.setSize(QSize(hsize_*hsplit_,vsize_*vsplit_));
136 void KWinGrid::updateGeometry(QRect& __new)
138 QRect newInner(inner_);
139 newInner.moveTopLeft(QPoint(__new.top()+(inner_.top()-outer_.top()),
140 __new.left()+(inner_.left()-outer_.left())));
141 newInner.setSize(QSize(__new.width()-(outer_.width()-inner_.width()),
142 __new.height()-(outer_.height()-inner_.height())));
147 void KWinGrid::applyGeometry()
149 XMoveResizeWindow(KApplication::kApplication()->getDisplay(),activeWindow_,
150 outer_.x(),outer_.y(),
151 inner_.width(),inner_.height());
152 KWin::setActiveWindow(activeWindow_);
157 void KWinGrid::move_TL()
162 void KWinGrid::move_TR()
167 void KWinGrid::move_BL()
172 void KWinGrid::move_BR()
174 move(hsplit_/2,vsplit_/2);
178 void KWinGrid::resize_Q()
180 resize(vsplit_/2,hsplit_/2);
183 void KWinGrid::resize_H()
185 resize(vsplit_,hsplit_/2);
188 void KWinGrid::resize_V()
190 resize(vsplit_/2,hsplit_);
193 void KWinGrid::resize_F()
195 resize(vsplit_,hsplit_);
199 void KWinGrid::move_L()
204 void KWinGrid::move_R()
209 void KWinGrid::move_U()
214 void KWinGrid::move_D()
220 void KWinGrid::resize_IH()
225 void KWinGrid::resize_DH()
227 resizeRelative(-1,0);
230 void KWinGrid::resize_IV()
235 void KWinGrid::resize_DV()
237 resizeRelative(0,-1);