22
22
#define NUM_HANDLES 9
23
23
#define FADE_MSEC UnityMTGrabHandlesScreen::get (screen)->optionGetFadeDuration ()
25
COMPIZ_PLUGIN_20090315 (unitymtgrabhandles, UnityMTGrabHandlesPluginVTable);
28
Unity::MT::GrabHandle::reposition (CompPoint *p, bool hard)
33
UMTGH_SCREEN (screen);
35
us->cScreen->damageRegion ((CompRect &) *this);
48
vm |= (CWStackMode | CWSibling);
50
xwc.stack_mode = Above;
55
XConfigureWindow (screen->dpy (), mIpw, vm, &xwc);
56
XSelectInput (screen->dpy (), mIpw, ButtonPressMask | ButtonReleaseMask);
59
us->cScreen->damageRegion ((CompRect &) *this);
63
Unity::MT::GrabHandle::hide ()
66
XUnmapWindow (screen->dpy (), mIpw);
70
Unity::MT::GrabHandle::show ()
74
XSetWindowAttributes xswa;
76
xswa.override_redirect = TRUE;
78
mIpw = XCreateWindow (screen->dpy (),
81
mTexture->second.width (),
82
mTexture->second.height (),
84
CopyFromParent, InputOnly,
85
CopyFromParent, CWOverrideRedirect, &xswa);
87
UnityMTGrabHandlesScreen::get (screen)->addHandleWindow (this, mIpw);
89
reposition (NULL, true);
92
XMapWindow (screen->dpy (), mIpw);
25
COMPIZ_PLUGIN_20090315(unitymtgrabhandles, UnityMTGrabHandlesPluginVTable);
28
Unity::MT::GrabHandle::reposition(CompPoint* p, bool hard)
35
us->cScreen->damageRegion((CompRect&) *this);
48
vm |= (CWStackMode | CWSibling);
50
xwc.stack_mode = Above;
55
XConfigureWindow(screen->dpy(), mIpw, vm, &xwc);
56
XSelectInput(screen->dpy(), mIpw, ButtonPressMask | ButtonReleaseMask);
59
us->cScreen->damageRegion((CompRect&) *this);
63
Unity::MT::GrabHandle::hide()
66
XUnmapWindow(screen->dpy(), mIpw);
70
Unity::MT::GrabHandle::show()
74
XSetWindowAttributes xswa;
76
xswa.override_redirect = TRUE;
78
mIpw = XCreateWindow(screen->dpy(),
81
mTexture->second.width(),
82
mTexture->second.height(),
84
CopyFromParent, InputOnly,
85
CopyFromParent, CWOverrideRedirect, &xswa);
87
UnityMTGrabHandlesScreen::get(screen)->addHandleWindow(this, mIpw);
89
reposition(NULL, true);
92
XMapWindow(screen->dpy(), mIpw);
95
95
Unity::MT::TextureLayout
96
Unity::MT::GrabHandle::layout ()
98
return TextureLayout (&mTexture->first, (CompRect *) this);
101
Unity::MT::GrabHandle::GrabHandle (TextureSize *t, Window owner, unsigned int id) :
112
Unity::MT::GrabHandle::~GrabHandle ()
116
UnityMTGrabHandlesScreen::get (screen)->removeHandleWindow (mIpw);
118
XDestroyWindow (screen->dpy (), mIpw);
123
Unity::MT::GrabHandle::handleButtonPress (XButtonEvent *be)
125
/* Send _NET_MOVERESIZE to root window so that a button-1
126
* press on this window will start resizing the window around */
129
w = screen->findTopLevelWindow (mOwner, false);
134
if (screen->getOption ("raise_on_click"))
135
w->updateAttributes (CompStackingUpdateModeAboveFullscreen);
137
if (w->id () != screen->activeWindow ())
139
w->moveInputFocusTo ();
141
event.xclient.type = ClientMessage;
142
event.xclient.display = screen->dpy ();
144
event.xclient.serial = 0;
145
event.xclient.send_event = true;
147
/* FIXME: Need to call findWindow since we need to send the
148
* _NET_WM_MOVERESIZE request to the client not the frame
149
* which we are tracking. That's a bit shitty */
150
event.xclient.window = w->id ();
151
event.xclient.message_type = Atoms::wmMoveResize;
152
event.xclient.format = 32;
154
event.xclient.data.l[0] = be->x_root;
155
event.xclient.data.l[1] = be->y_root;
156
event.xclient.data.l[2] = mId;
157
event.xclient.data.l[3] = be->button;
158
event.xclient.data.l[4] = 1;
160
XSendEvent (screen->dpy (), screen->root (), false,
161
SubstructureRedirectMask | SubstructureNotifyMask,
166
Unity::MT::GrabHandleGroup::show ()
168
foreach (Unity::MT::GrabHandle &handle, *this)
175
Unity::MT::GrabHandleGroup::hide ()
177
foreach (Unity::MT::GrabHandle &handle, *this)
96
Unity::MT::GrabHandle::layout()
98
return TextureLayout(&mTexture->first, (CompRect*) this);
101
Unity::MT::GrabHandle::GrabHandle(TextureSize* t, Window owner, unsigned int id) :
112
Unity::MT::GrabHandle::~GrabHandle()
116
UnityMTGrabHandlesScreen::get(screen)->removeHandleWindow(mIpw);
118
XDestroyWindow(screen->dpy(), mIpw);
123
Unity::MT::GrabHandle::handleButtonPress(XButtonEvent* be)
125
/* Send _NET_MOVERESIZE to root window so that a button-1
126
* press on this window will start resizing the window around */
129
w = screen->findTopLevelWindow(mOwner, false);
134
if (screen->getOption("raise_on_click"))
135
w->updateAttributes(CompStackingUpdateModeAboveFullscreen);
137
if (w->id() != screen->activeWindow())
139
w->moveInputFocusTo();
141
event.xclient.type = ClientMessage;
142
event.xclient.display = screen->dpy();
144
event.xclient.serial = 0;
145
event.xclient.send_event = true;
147
/* FIXME: Need to call findWindow since we need to send the
148
* _NET_WM_MOVERESIZE request to the client not the frame
149
* which we are tracking. That's a bit shitty */
150
event.xclient.window = w->id();
151
event.xclient.message_type = Atoms::wmMoveResize;
152
event.xclient.format = 32;
154
event.xclient.data.l[0] = be->x_root;
155
event.xclient.data.l[1] = be->y_root;
156
event.xclient.data.l[2] = mId;
157
event.xclient.data.l[3] = be->button;
158
event.xclient.data.l[4] = 1;
160
XSendEvent(screen->dpy(), screen->root(), false,
161
SubstructureRedirectMask | SubstructureNotifyMask,
166
Unity::MT::GrabHandleGroup::show()
168
foreach(Unity::MT::GrabHandle & handle, *this)
175
Unity::MT::GrabHandleGroup::hide()
177
foreach(Unity::MT::GrabHandle & handle, *this)
184
Unity::MT::GrabHandleGroup::animate (unsigned int msec)
184
Unity::MT::GrabHandleGroup::animate(unsigned int msec)
186
mMoreAnimate = false;
192
mOpacity += ((float) msec / (float) FADE_MSEC) * OPAQUE;
194
if (mOpacity >= OPAQUE)
201
mOpacity -= ((float) msec / (float) FADE_MSEC) * OPAQUE;
213
mMoreAnimate = mState != NONE;
186
mMoreAnimate = false;
192
mOpacity += ((float) msec / (float) FADE_MSEC) * OPAQUE;
194
if (mOpacity >= OPAQUE)
201
mOpacity -= ((float) msec / (float) FADE_MSEC) * OPAQUE;
213
mMoreAnimate = mState != NONE;
219
Unity::MT::GrabHandleGroup::opacity ()
225
Unity::MT::GrabHandleGroup::visible ()
227
return mOpacity > 0.0f;
231
Unity::MT::GrabHandleGroup::needsAnimate ()
219
Unity::MT::GrabHandleGroup::opacity()
225
Unity::MT::GrabHandleGroup::visible()
227
return mOpacity > 0.0f;
231
Unity::MT::GrabHandleGroup::needsAnimate()
237
Unity::MT::GrabHandleGroup::relayout (const CompRect &rect, bool hard)
239
/* Each grab handle at each vertex, eg:
251
const float pos[9][2] = {
252
{0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f},
253
{1.0f, 0.5f}, {1.0f, 1.0f},
254
{0.5f, 1.0f}, {0.0f, 1.0f}, {0.0f, 0.5f},
255
{0.5f, 0.5f} /* middle */
258
for (unsigned int i = 0; i < NUM_HANDLES; i++)
260
Unity::MT::GrabHandle &handle = at (i);
261
CompPoint p (rect.x () + rect.width () * pos[i][0] -
263
rect.y () + rect.height () * pos[i][1] -
264
handle.height () / 2);
266
handle.reposition (&p, hard);
270
Unity::MT::GrabHandleGroup::GrabHandleGroup (Window owner) :
275
UMTGH_SCREEN (screen);
277
for (unsigned int i = 0; i < NUM_HANDLES; i++)
278
push_back (Unity::MT::GrabHandle (&us->textures ().at (i), owner, i));
281
Unity::MT::GrabHandleGroup::~GrabHandleGroup ()
283
UMTGH_SCREEN (screen);
285
foreach (Unity::MT::GrabHandle &handle, *this)
286
us->cScreen->damageRegion ((CompRect &) handle);
237
Unity::MT::GrabHandleGroup::relayout(const CompRect& rect, bool hard)
239
/* Each grab handle at each vertex, eg:
251
const float pos[9][2] =
253
{0.0f, 0.0f}, {0.5f, 0.0f}, {1.0f, 0.0f},
254
{1.0f, 0.5f}, {1.0f, 1.0f},
255
{0.5f, 1.0f}, {0.0f, 1.0f}, {0.0f, 0.5f},
256
{0.5f, 0.5f} /* middle */
259
for (unsigned int i = 0; i < NUM_HANDLES; i++)
261
Unity::MT::GrabHandle& handle = at(i);
262
CompPoint p(rect.x() + rect.width() * pos[i][0] -
264
rect.y() + rect.height() * pos[i][1] -
265
handle.height() / 2);
267
handle.reposition(&p, hard);
271
Unity::MT::GrabHandleGroup::GrabHandleGroup(Window owner) :
276
UMTGH_SCREEN(screen);
278
for (unsigned int i = 0; i < NUM_HANDLES; i++)
279
push_back(Unity::MT::GrabHandle(&us->textures().at(i), owner, i));
282
Unity::MT::GrabHandleGroup::~GrabHandleGroup()
284
UMTGH_SCREEN(screen);
286
foreach(Unity::MT::GrabHandle & handle, *this)
287
us->cScreen->damageRegion((CompRect&) handle);
289
290
std::vector <Unity::MT::TextureLayout>
290
Unity::MT::GrabHandleGroup::layout ()
291
Unity::MT::GrabHandleGroup::layout()
292
std::vector <Unity::MT::TextureLayout> layout;
294
foreach (Unity::MT::GrabHandle &handle, *this)
295
layout.push_back (handle.layout ());
293
std::vector <Unity::MT::TextureLayout> layout;
295
foreach(Unity::MT::GrabHandle & handle, *this)
296
layout.push_back(handle.layout());
300
301
/* Super speed hack */
302
sortPointers (const CompWindow *p1, const CompWindow *p2)
303
sortPointers(const CompWindow* p1, const CompWindow* p2)
304
return (void *) p1 < (void *) p2;
305
return (void*) p1 < (void*) p2;
308
UnityMTGrabHandlesScreen::handleEvent (XEvent *event)
309
UnityMTGrabHandlesScreen::handleEvent(XEvent* event)
310
Unity::MT::GrabHandle *handle;
311
std::map <Window, Unity::MT::GrabHandle *>::iterator it;
312
CompWindow *w, *oldPrev, *oldNext;
314
w = oldPrev = oldNext = NULL;
320
if (event->xfocus.mode == NotifyUngrab)
322
foreach (CompWindow *w, screen->windows ())
324
UnityMTGrabHandlesWindow *mtwindow = UnityMTGrabHandlesWindow::get (w);
325
if (mtwindow->handleTimerActive ())
326
mtwindow->resetTimer ();
332
if (event->xclient.message_type == mCompResizeWindowAtom)
311
Unity::MT::GrabHandle* handle;
312
std::map <Window, Unity::MT::GrabHandle*>::iterator it;
313
CompWindow* w, *oldPrev, *oldNext;
315
w = oldPrev = oldNext = NULL;
321
if (event->xfocus.mode == NotifyUngrab)
323
foreach(CompWindow * w, screen->windows())
325
UnityMTGrabHandlesWindow* mtwindow = UnityMTGrabHandlesWindow::get(w);
326
if (mtwindow->handleTimerActive())
327
mtwindow->resetTimer();
333
if (event->xclient.message_type == mCompResizeWindowAtom)
335
CompWindow* w = screen->findWindow(event->xclient.window);
342
r.setGeometry(event->xclient.data.l[0] - w->input().left,
343
event->xclient.data.l[1] - w->input().top,
344
event->xclient.data.l[2] + w->input().left + w->input().right,
345
event->xclient.data.l[3] + w->input().top + w->input().bottom);
347
uw->relayout(r, false);
355
/* Stacking order of managed clients changed, check old
356
* stacking order and ensure stacking of handles
357
* that were changed in the stack */
360
if (event->xproperty.atom == Atoms::clientListStacking)
362
CompWindowVector invalidated(0);
363
CompWindowVector clients = screen->clientList(true);
364
CompWindowVector oldClients = mLastClientListStacking;
365
CompWindowVector clientListStacking = screen->clientList(true);
366
/* Windows can be removed and added from the client list
367
* here at the same time (eg hide/unhide launcher ... racy)
368
* so we need to check if the client list contains the same
369
* windows as it used to. Sort both lists and compare ... */
371
std::sort(clients.begin(), clients.end(), sortPointers);
372
std::sort(oldClients.begin(),
373
oldClients.end(), sortPointers);
375
if (clients != mLastClientListStacking)
376
invalidated = clients;
379
CompWindowVector::const_iterator cit = clientListStacking.begin();
380
CompWindowVector::const_iterator oit = mLastClientListStacking.begin();
382
for (; cit != clientListStacking.end(); cit++, oit++)
384
/* All clients from this point onwards in cit are invalidated
385
* so splice the list to the end of the new client list
386
* and update the stacking of handles there */
387
if ((*cit)->id() != (*oit)->id())
334
CompWindow *w = screen->findWindow (event->xclient.window);
341
r.setGeometry (event->xclient.data.l[0] - w->input ().left,
342
event->xclient.data.l[1] - w->input ().top,
343
event->xclient.data.l[2] + w->input ().left + w->input ().right,
344
event->xclient.data.l[3] + w->input ().top + w->input ().bottom);
346
uw->relayout (r, false);
389
invalidated.push_back((*cit));
354
/* Stacking order of managed clients changed, check old
355
* stacking order and ensure stacking of handles
356
* that were changed in the stack */
359
if (event->xproperty.atom == Atoms::clientListStacking)
361
CompWindowVector invalidated (0);
362
CompWindowVector clients = screen->clientList (true);
363
CompWindowVector oldClients = mLastClientListStacking;
364
CompWindowVector clientListStacking = screen->clientList (true);
365
/* Windows can be removed and added from the client list
366
* here at the same time (eg hide/unhide launcher ... racy)
367
* so we need to check if the client list contains the same
368
* windows as it used to. Sort both lists and compare ... */
370
std::sort (clients.begin (), clients.end (), sortPointers);
371
std::sort (oldClients.begin (),
372
oldClients.end (), sortPointers);
374
if (clients != mLastClientListStacking)
375
invalidated = clients;
378
CompWindowVector::const_iterator cit = clientListStacking.begin ();
379
CompWindowVector::const_iterator oit = mLastClientListStacking.begin ();
381
for (; cit != clientListStacking.end (); cit++, oit++)
383
/* All clients from this point onwards in cit are invalidated
384
* so splice the list to the end of the new client list
385
* and update the stacking of handles there */
386
if ((*cit)->id () != (*oit)->id ())
388
invalidated.push_back ((*cit));
393
foreach (CompWindow *w, invalidated)
394
UnityMTGrabHandlesWindow::get (w)->restackHandles ();
396
mLastClientListStacking = clients;
403
if (event->xbutton.button != 1)
406
it = mInputHandles.find (event->xbutton.window);
408
if (it != mInputHandles.end ())
412
handle->handleButtonPress ((XButtonEvent *) event);
416
case ConfigureNotify:
418
w = screen->findTopLevelWindow (event->xconfigure.window);
421
UnityMTGrabHandlesWindow::get (w)->relayout (w->inputRect (), true);
427
it = mInputHandles.find (event->xmap.window);
429
if (it != mInputHandles.end ())
432
it->second->reposition (NULL, true);
441
screen->handleEvent (event);
445
UnityMTGrabHandlesScreen::donePaint ()
449
foreach (Unity::MT::GrabHandleGroup *handles, mGrabHandles)
451
if (handles->needsAnimate ())
453
foreach (Unity::MT::GrabHandle &handle, *handles)
454
cScreen->damageRegion ((CompRect &) handle);
459
cScreen->donePaint ();
463
UnityMTGrabHandlesScreen::preparePaint (int msec)
467
mMoreAnimate = false;
469
foreach (Unity::MT::GrabHandleGroup *handles, mGrabHandles)
471
mMoreAnimate |= handles->animate (msec);
475
cScreen->preparePaint (msec);
394
foreach(CompWindow * w, invalidated)
395
UnityMTGrabHandlesWindow::get(w)->restackHandles();
397
mLastClientListStacking = clients;
404
if (event->xbutton.button != 1)
407
it = mInputHandles.find(event->xbutton.window);
409
if (it != mInputHandles.end())
413
handle->handleButtonPress((XButtonEvent*) event);
417
case ConfigureNotify:
419
w = screen->findTopLevelWindow(event->xconfigure.window);
422
UnityMTGrabHandlesWindow::get(w)->relayout(w->inputRect(), true);
428
it = mInputHandles.find(event->xmap.window);
430
if (it != mInputHandles.end())
433
it->second->reposition(NULL, true);
442
screen->handleEvent(event);
446
UnityMTGrabHandlesScreen::donePaint()
450
foreach(Unity::MT::GrabHandleGroup * handles, mGrabHandles)
452
if (handles->needsAnimate())
454
foreach(Unity::MT::GrabHandle & handle, *handles)
455
cScreen->damageRegion((CompRect&) handle);
460
cScreen->donePaint();
464
UnityMTGrabHandlesScreen::preparePaint(int msec)
468
mMoreAnimate = false;
470
foreach(Unity::MT::GrabHandleGroup * handles, mGrabHandles)
472
mMoreAnimate |= handles->animate(msec);
476
cScreen->preparePaint(msec);
479
UnityMTGrabHandlesWindow::handleTimerActive ()
480
UnityMTGrabHandlesWindow::handleTimerActive()
481
482
return _timer_handle != 0;
485
UnityMTGrabHandlesWindow::allowHandles ()
486
UnityMTGrabHandlesWindow::allowHandles()
487
/* Not on windows we can't move or resize */
488
if (!(window->actions () & CompWindowActionResizeMask))
491
if (!(window->actions () & CompWindowActionMoveMask))
494
/* Not on override redirect windows */
495
if (window->overrideRedirect ())
488
/* Not on windows we can't move or resize */
489
if (!(window->actions() & CompWindowActionResizeMask))
492
if (!(window->actions() & CompWindowActionMoveMask))
495
/* Not on override redirect windows */
496
if (window->overrideRedirect())
502
UnityMTGrabHandlesWindow::getOutputExtents (CompWindowExtents &output)
503
UnityMTGrabHandlesWindow::getOutputExtents(CompWindowExtents& output)
506
/* Only care about the handle on the outside */
507
output.left = MAX (output.left, window->borderRect ().left () + mHandles->at (0).width () / 2);
508
output.right = MAX (output.right, window->borderRect ().right () + mHandles->at (0).width () / 2);
509
output.top = MAX (output.top, window->borderRect ().top () + mHandles->at (0).height () / 2);
510
output.bottom = MAX (output.bottom, window->borderRect ().bottom () + mHandles->at (0).height () / 2);
513
window->getOutputExtents (output);
507
/* Only care about the handle on the outside */
508
output.left = MAX(output.left, window->borderRect().left() + mHandles->at(0).width() / 2);
509
output.right = MAX(output.right, window->borderRect().right() + mHandles->at(0).width() / 2);
510
output.top = MAX(output.top, window->borderRect().top() + mHandles->at(0).height() / 2);
511
output.bottom = MAX(output.bottom, window->borderRect().bottom() + mHandles->at(0).height() / 2);
514
window->getOutputExtents(output);
518
UnityMTGrabHandlesWindow::glDraw (const GLMatrix &transform,
519
GLFragment::Attrib &fragment,
520
const CompRegion ®ion,
519
UnityMTGrabHandlesWindow::glDraw(const GLMatrix& transform,
520
GLFragment::Attrib& fragment,
521
const CompRegion& region,
523
/* Draw the window on the bottom, we will be drawing the
525
bool status = gWindow->glDraw (transform, fragment, region, mask);
527
UMTGH_SCREEN (screen);
529
if (mHandles && mHandles->visible ())
524
/* Draw the window on the bottom, we will be drawing the
526
bool status = gWindow->glDraw(transform, fragment, region, mask);
528
UMTGH_SCREEN(screen);
530
if (mHandles && mHandles->visible())
532
unsigned int handle = 0;
534
foreach(Unity::MT::TextureLayout layout, mHandles->layout())
531
unsigned int handle = 0;
533
foreach (Unity::MT::TextureLayout layout, mHandles->layout ())
535
/* We want to set the geometry of the dim to the window
537
CompRegion reg = CompRegion (*layout.second);
543
unsigned int handles[9];
546
const struct _skipInfo skip[3] = {
547
{CompWindowStateMaximizedVertMask,
548
CompWindowStateMaximizedVertMask,
549
{ 1, 1, 1, 0, 1, 1, 1, 0, 0 }},
550
{CompWindowStateMaximizedHorzMask,
551
CompWindowStateMaximizedHorzMask,
552
{1, 0, 1, 1, 1, 0, 1, 1, 0 }},
553
{CompWindowStateMaximizedVertMask,
554
CompWindowStateMaximizedHorzMask,
555
{1, 1, 1, 1, 1, 1, 1, 1, 1 }}};
557
foreach (GLTexture *tex, *layout.first)
536
/* We want to set the geometry of the dim to the window
538
CompRegion reg = CompRegion(*layout.second);
544
unsigned int handles[9];
547
const struct _skipInfo skip[3] =
550
CompWindowStateMaximizedVertMask,
551
CompWindowStateMaximizedVertMask,
552
{ 1, 1, 1, 0, 1, 1, 1, 0, 0 }
555
CompWindowStateMaximizedHorzMask,
556
CompWindowStateMaximizedHorzMask,
557
{1, 0, 1, 1, 1, 0, 1, 1, 0 }
560
CompWindowStateMaximizedVertMask,
561
CompWindowStateMaximizedHorzMask,
562
{1, 1, 1, 1, 1, 1, 1, 1, 1 }
566
foreach(GLTexture * tex, *layout.first)
568
GLTexture::MatrixList matl;
569
GLTexture::Matrix mat = tex->matrix();
570
CompRegion paintRegion(region);
571
bool skipHandle = false;
573
for (unsigned int j = 0; j < 3; j++)
575
if (skip[j].vstate & window->state() &&
576
skip[j].hstate & window->state())
578
if (skip[j].handles[handle])
559
GLTexture::MatrixList matl;
560
GLTexture::Matrix mat = tex->matrix ();
561
CompRegion paintRegion (region);
562
bool skipHandle = false;
564
for (unsigned int j = 0; j < 3; j++)
566
if (skip[j].vstate & window->state () &&
567
skip[j].hstate & window->state ())
569
if (skip[j].handles[handle])
580
/* We can reset the window geometry since it will be
582
gWindow->geometry ().reset ();
584
/* Scale the handles */
588
/* Not sure what this does, but it is necessary
589
* (adjusts for scale?) */
590
mat.x0 -= mat.xx * reg.boundingRect ().x1 ();
591
mat.y0 -= mat.yy * reg.boundingRect ().y1 ();
593
matl.push_back (mat);
595
if (mask & PAINT_WINDOW_TRANSFORMED_MASK)
596
paintRegion = infiniteRegion;
598
/* Now allow plugins to mess with the geometry of our
599
* dim (so we get a nice render for things like
601
gWindow->glAddGeometry (matl, reg, paintRegion);
603
/* Did it succeed? */
604
if (gWindow->geometry ().vertices)
606
fragment.setOpacity (mHandles->opacity ());
607
/* Texture rendering set-up */
608
us->gScreen->setTexEnvMode (GL_MODULATE);
609
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
610
/* Draw the dim texture with all of it's modified
612
gWindow->glDrawTexture (tex, fragment, mask | PAINT_WINDOW_BLEND_MASK
613
| PAINT_WINDOW_TRANSLUCENT_MASK |
614
PAINT_WINDOW_TRANSFORMED_MASK);
615
/* Texture rendering tear-down */
616
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
617
us->gScreen->setTexEnvMode (GL_REPLACE);
589
/* We can reset the window geometry since it will be
591
gWindow->geometry().reset();
593
/* Scale the handles */
597
/* Not sure what this does, but it is necessary
598
* (adjusts for scale?) */
599
mat.x0 -= mat.xx * reg.boundingRect().x1();
600
mat.y0 -= mat.yy * reg.boundingRect().y1();
604
if (mask & PAINT_WINDOW_TRANSFORMED_MASK)
605
paintRegion = infiniteRegion;
607
/* Now allow plugins to mess with the geometry of our
608
* dim (so we get a nice render for things like
610
gWindow->glAddGeometry(matl, reg, paintRegion);
612
/* Did it succeed? */
613
if (gWindow->geometry().vertices)
615
fragment.setOpacity(mHandles->opacity());
616
/* Texture rendering set-up */
617
us->gScreen->setTexEnvMode(GL_MODULATE);
618
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
619
/* Draw the dim texture with all of it's modified
621
gWindow->glDrawTexture(tex, fragment, mask | PAINT_WINDOW_BLEND_MASK
622
| PAINT_WINDOW_TRANSLUCENT_MASK |
623
PAINT_WINDOW_TRANSFORMED_MASK);
624
/* Texture rendering tear-down */
625
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
626
us->gScreen->setTexEnvMode(GL_REPLACE);
629
UnityMTGrabHandlesWindow::relayout (const CompRect &r, bool hard)
632
mHandles->relayout (r, hard);
636
UnityMTGrabHandlesWindow::grabNotify (int x, int y, unsigned int state, unsigned int mask)
638
window->grabNotify (x, y, state, mask);
642
UnityMTGrabHandlesWindow::moveNotify (int dx, int dy, bool immediate)
645
mHandles->relayout ((const CompRect &) window->inputRect (), false);
647
window->moveNotify (dx, dy, immediate);
651
UnityMTGrabHandlesWindow::ungrabNotify ()
653
window->ungrabNotify ();
638
UnityMTGrabHandlesWindow::relayout(const CompRect& r, bool hard)
641
mHandles->relayout(r, hard);
645
UnityMTGrabHandlesWindow::grabNotify(int x, int y, unsigned int state, unsigned int mask)
647
window->grabNotify(x, y, state, mask);
651
UnityMTGrabHandlesWindow::moveNotify(int dx, int dy, bool immediate)
654
mHandles->relayout((const CompRect&) window->inputRect(), false);
656
window->moveNotify(dx, dy, immediate);
660
UnityMTGrabHandlesWindow::ungrabNotify()
662
window->ungrabNotify();
657
UnityMTGrabHandlesWindow::handlesVisible ()
666
UnityMTGrabHandlesWindow::handlesVisible()
662
return mHandles->visible ();
671
return mHandles->visible();
666
UnityMTGrabHandlesWindow::hideHandles ()
675
UnityMTGrabHandlesWindow::hideHandles()
671
window->updateWindowOutputExtents ();
672
cWindow->damageOutputExtents ();
680
window->updateWindowOutputExtents();
681
cWindow->damageOutputExtents();
678
UnityMTGrabHandlesWindow::onHideTimeout (gpointer data)
680
UnityMTGrabHandlesWindow *self = static_cast<UnityMTGrabHandlesWindow*> (data);
682
if (screen->grabbed ())
686
self->hideHandles ();
687
self->_mt_screen->mMoreAnimate = true;
688
self->_timer_handle = 0;
693
UnityMTGrabHandlesWindow::resetTimer ()
696
g_source_remove (_timer_handle);
698
_timer_handle = g_timeout_add (2000, &UnityMTGrabHandlesWindow::onHideTimeout, this);
702
UnityMTGrabHandlesWindow::disableTimer ()
705
g_source_remove (_timer_handle);
709
UnityMTGrabHandlesWindow::showHandles (bool use_timer)
713
mHandles = new Unity::MT::GrabHandleGroup (window->frame ());
714
UnityMTGrabHandlesScreen::get (screen)->addHandles (mHandles);
717
if (!mHandles->visible ())
721
mHandles->relayout (window->inputRect (), true);
723
window->updateWindowOutputExtents ();
724
cWindow->damageOutputExtents ();
687
UnityMTGrabHandlesWindow::onHideTimeout(gpointer data)
689
UnityMTGrabHandlesWindow* self = static_cast<UnityMTGrabHandlesWindow*>(data);
691
if (screen->grabbed())
696
self->_mt_screen->mMoreAnimate = true;
697
self->_timer_handle = 0;
702
UnityMTGrabHandlesWindow::resetTimer()
705
g_source_remove(_timer_handle);
707
_timer_handle = g_timeout_add(2000, &UnityMTGrabHandlesWindow::onHideTimeout, this);
711
UnityMTGrabHandlesWindow::disableTimer()
714
g_source_remove(_timer_handle);
718
UnityMTGrabHandlesWindow::showHandles(bool use_timer)
722
mHandles = new Unity::MT::GrabHandleGroup(window->frame());
723
UnityMTGrabHandlesScreen::get(screen)->addHandles(mHandles);
726
if (!mHandles->visible())
730
mHandles->relayout(window->inputRect(), true);
732
window->updateWindowOutputExtents();
733
cWindow->damageOutputExtents();
743
UnityMTGrabHandlesWindow::restackHandles()
748
foreach(Unity::MT::GrabHandle & handle, *mHandles)
749
handle.reposition(NULL, true);
753
UnityMTGrabHandlesScreen::addHandleWindow(Unity::MT::GrabHandle* h, Window w)
755
mInputHandles.insert(std::pair <Window, Unity::MT::GrabHandle*> (w, h));
759
UnityMTGrabHandlesScreen::removeHandleWindow(Window w)
761
mInputHandles.erase(w);
765
UnityMTGrabHandlesScreen::addHandles(Unity::MT::GrabHandleGroup* handles)
767
mGrabHandles.push_back(handles);
771
UnityMTGrabHandlesScreen::removeHandles(Unity::MT::GrabHandleGroup* handles)
773
mGrabHandles.remove(handles);
779
UnityMTGrabHandlesScreen::toggleHandles(CompAction* action,
780
CompAction::State state,
781
CompOption::Vector& options)
783
CompWindow* w = screen->findWindow(CompOption::getIntOptionNamed(options,
790
if (!uw->allowHandles())
793
if (uw->handlesVisible())
734
UnityMTGrabHandlesWindow::restackHandles ()
739
foreach (Unity::MT::GrabHandle &handle, *mHandles)
740
handle.reposition (NULL, true);
744
UnityMTGrabHandlesScreen::addHandleWindow (Unity::MT::GrabHandle *h, Window w)
746
mInputHandles.insert (std::pair <Window, Unity::MT::GrabHandle *> (w, h));
750
UnityMTGrabHandlesScreen::removeHandleWindow (Window w)
752
mInputHandles.erase (w);
756
UnityMTGrabHandlesScreen::addHandles (Unity::MT::GrabHandleGroup *handles)
758
mGrabHandles.push_back (handles);
762
UnityMTGrabHandlesScreen::removeHandles (Unity::MT::GrabHandleGroup *handles)
764
mGrabHandles.remove (handles);
796
uw->showHandles(true);
766
798
mMoreAnimate = true;
770
UnityMTGrabHandlesScreen::toggleHandles (CompAction *action,
771
CompAction::State state,
772
CompOption::Vector &options)
774
CompWindow *w = screen->findWindow (CompOption::getIntOptionNamed (options,
781
if (!uw->allowHandles ())
784
if (uw->handlesVisible ())
787
uw->showHandles (true);
796
UnityMTGrabHandlesScreen::showHandles (CompAction *action,
797
CompAction::State state,
798
CompOption::Vector &options)
800
CompWindow *w = screen->findWindow (CompOption::getIntOptionNamed (options,
804
bool use_timer = CompOption::getBoolOptionNamed (options, "use-timer", true);
810
if (!uw->allowHandles ())
813
uw->showHandles (use_timer);
815
if (!uw->handlesVisible ())
823
UnityMTGrabHandlesScreen::hideHandles (CompAction *action,
824
CompAction::State state,
825
CompOption::Vector &options)
827
CompWindow *w = screen->findWindow (CompOption::getIntOptionNamed (options,
834
if (!uw->allowHandles ())
837
if (uw->handlesVisible ())
847
UnityMTGrabHandlesScreen::UnityMTGrabHandlesScreen (CompScreen *s) :
848
PluginClassHandler <UnityMTGrabHandlesScreen, CompScreen> (s),
849
cScreen (CompositeScreen::get (s)),
850
gScreen (GLScreen::get (s)),
853
mLastClientListStacking (screen->clientList (true)),
854
mCompResizeWindowAtom (XInternAtom (screen->dpy (),
855
"_COMPIZ_RESIZE_NOTIFY", 0)),
858
ScreenInterface::setHandler (s);
859
CompositeScreenInterface::setHandler (cScreen);
860
GLScreenInterface::setHandler (gScreen);
862
mHandleTextures.resize (NUM_HANDLES);
864
for (unsigned int i = 0; i < NUM_HANDLES; i++)
866
CompString fname = "handle-";
867
CompString pname ("unitymtgrabhandles");
869
fname = compPrintf ("%s%i.png", fname.c_str (), i);
870
mHandleTextures.at (i).first =
871
GLTexture::readImageToTexture (fname, pname,
872
mHandleTextures.at (i).second);
875
optionSetToggleHandlesKeyInitiate (boost::bind (&UnityMTGrabHandlesScreen::toggleHandles, this, _1, _2, _3));
876
optionSetShowHandlesKeyInitiate (boost::bind (&UnityMTGrabHandlesScreen::showHandles, this, _1, _2, _3));
877
optionSetHideHandlesKeyInitiate (boost::bind (&UnityMTGrabHandlesScreen::hideHandles, this, _1, _2, _3));
880
UnityMTGrabHandlesScreen::~UnityMTGrabHandlesScreen ()
882
while (mGrabHandles.size ())
884
Unity::MT::GrabHandleGroup *handles = mGrabHandles.back ();
886
mGrabHandles.pop_back ();
889
mHandleTextures.clear ();
892
UnityMTGrabHandlesWindow::UnityMTGrabHandlesWindow (CompWindow *w) :
893
PluginClassHandler <UnityMTGrabHandlesWindow, CompWindow> (w),
895
cWindow (CompositeWindow::get (w)),
896
gWindow (GLWindow::get (w)),
899
WindowInterface::setHandler (window);
900
CompositeWindowInterface::setHandler (cWindow);
901
GLWindowInterface::setHandler (gWindow);
904
_mt_screen = UnityMTGrabHandlesScreen::get (screen);
908
UnityMTGrabHandlesWindow::~UnityMTGrabHandlesWindow ()
911
g_source_remove (_timer_handle);
915
UnityMTGrabHandlesScreen::get (screen)->removeHandles (mHandles);
923
UnityMTGrabHandlesPluginVTable::init ()
925
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
926
!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) ||
927
!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
805
UnityMTGrabHandlesScreen::showHandles(CompAction* action,
806
CompAction::State state,
807
CompOption::Vector& options)
809
CompWindow* w = screen->findWindow(CompOption::getIntOptionNamed(options,
813
bool use_timer = CompOption::getBoolOptionNamed(options, "use-timer", true);
819
if (!uw->allowHandles())
822
uw->showHandles(use_timer);
824
if (!uw->handlesVisible())
832
UnityMTGrabHandlesScreen::hideHandles(CompAction* action,
833
CompAction::State state,
834
CompOption::Vector& options)
836
CompWindow* w = screen->findWindow(CompOption::getIntOptionNamed(options,
843
if (!uw->allowHandles())
846
if (uw->handlesVisible())
856
UnityMTGrabHandlesScreen::UnityMTGrabHandlesScreen(CompScreen* s) :
857
PluginClassHandler <UnityMTGrabHandlesScreen, CompScreen> (s),
858
cScreen(CompositeScreen::get(s)),
859
gScreen(GLScreen::get(s)),
862
mLastClientListStacking(screen->clientList(true)),
863
mCompResizeWindowAtom(XInternAtom(screen->dpy(),
864
"_COMPIZ_RESIZE_NOTIFY", 0)),
867
ScreenInterface::setHandler(s);
868
CompositeScreenInterface::setHandler(cScreen);
869
GLScreenInterface::setHandler(gScreen);
871
mHandleTextures.resize(NUM_HANDLES);
873
for (unsigned int i = 0; i < NUM_HANDLES; i++)
875
CompString fname = "handle-";
876
CompString pname("unitymtgrabhandles");
878
fname = compPrintf("%s%i.png", fname.c_str(), i);
879
mHandleTextures.at(i).first =
880
GLTexture::readImageToTexture(fname, pname,
881
mHandleTextures.at(i).second);
884
optionSetToggleHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::toggleHandles, this, _1, _2, _3));
885
optionSetShowHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::showHandles, this, _1, _2, _3));
886
optionSetHideHandlesKeyInitiate(boost::bind(&UnityMTGrabHandlesScreen::hideHandles, this, _1, _2, _3));
889
UnityMTGrabHandlesScreen::~UnityMTGrabHandlesScreen()
891
while (mGrabHandles.size())
893
Unity::MT::GrabHandleGroup* handles = mGrabHandles.back();
895
mGrabHandles.pop_back();
898
mHandleTextures.clear();
901
UnityMTGrabHandlesWindow::UnityMTGrabHandlesWindow(CompWindow* w) :
902
PluginClassHandler <UnityMTGrabHandlesWindow, CompWindow> (w),
904
cWindow(CompositeWindow::get(w)),
905
gWindow(GLWindow::get(w)),
908
WindowInterface::setHandler(window);
909
CompositeWindowInterface::setHandler(cWindow);
910
GLWindowInterface::setHandler(gWindow);
913
_mt_screen = UnityMTGrabHandlesScreen::get(screen);
917
UnityMTGrabHandlesWindow::~UnityMTGrabHandlesWindow()
920
g_source_remove(_timer_handle);
924
UnityMTGrabHandlesScreen::get(screen)->removeHandles(mHandles);
932
UnityMTGrabHandlesPluginVTable::init()
934
if (!CompPlugin::checkPluginABI("core", CORE_ABIVERSION) ||
935
!CompPlugin::checkPluginABI("composite", COMPIZ_COMPOSITE_ABI) ||
936
!CompPlugin::checkPluginABI("opengl", COMPIZ_OPENGL_ABI))