1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
|
//-*-c++-*-
// -------------------------------------------
// RCS data:
// $Date: 2003/06/23 14:47:22 $
// $Revision: 1.1.1.1 $
// $Source: /cvsroot/miwm/miwm/miwm/client.cc,v $
// $Id: client.cc,v 1.1.1.1 2003/06/23 14:47:22 bwise837 Exp $
// $RCSfile: client.cc,v $
// -------------------------------------------
// Copyright by Ben Paul Wise.
// -------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// -------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "miwm.h"
#include "client.h"
#include "struct.h"
#include "ws.h"
Client *current;
int highestClientID = 0;
Edge interacting_edge;
static void sendcmessage(Window, Atom, long, long);
// -------------------------------------------
void
setactive(Client *c, int on, long timestamp) {
int inhibit = isshaped(c->window);
if (c == 0 || hidden(c))
return;
if (!inhibit) {
if (on && c->accepts_focus && c->name) {
XMoveResizeWindow(dpy, c->parent,
c->size.x, c->size.y - titleHeight(),
c->size.width, c->size.height + titleHeight());
XMoveWindow(dpy, c->window, border, border + titleHeight());
} else {
XMoveResizeWindow(dpy, c->parent, c->size.x, c->size.y,
c->size.width, c->size.height);
XMoveWindow(dpy, c->window, border, border);
}
}
if (on && c->accepts_focus) {
XSetInputFocus(dpy, c->window, RevertToPointerRoot, CurrentTime);
if (c->proto & Ptakefocus)
sendcmessage(c->window, wm_protocols, wm_take_focus, timestamp);
cmapfocus(c);
}
if (!inhibit)
theWM->drawClientBorder(c, on);
return;
}
Client *getClient(Window w) {
Client *c;
Node *cND;
if (w == 0 || w == root)
return 0;
// find the client corresponding to this window.
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
// if this client is NULL, we are in deep doo doo
assert (NULL != c);
if (c->window == w || c->parent == w)
return c;
}
// Nothing found.
return NULL;
}
Client* addClient(Window w) {
Client* c;
if (w == 0 || w == root)
return 0;
// see if we already have a client corresponding to this window.
c = getClient(w);
if (c != NULL)
return c;
// Because this is 'calloc' rather than 'new',
// I can not use my memory-leak detector to
// look for leaks.
// This is 'calloc' rather than 'new' because
// I could never get it to work when I allocate
// via 'new'. The attributes are initialized differently,
// and I can not figure out how.
//c = (Client*) calloc(1, sizeof *c);
c = new Client();
c->opaqueMoveP = 0; // default is wire-move
c->gripEdge = ENone;
c->boxStatus = DBundrawn;
c->outlinedP = 0;
c->sticky = 0;
c->window = w;
c->parent = root;
c->hidden = False;
c->isMapped = 1;
c->state = WithdrawnState;
c->internal_state = INormal;
c->cmap = None;
c->name = NULL;
c->fallback_name = NULL;
c->ncmapwins = 0;
c->cmapwins = 0;
c->wmcmaps = 0;
c->accepts_focus = 1;
c->workSpace = theWM->workSpace;
c->clientID = highestClientID;
c->next = NULL;
highestClientID = highestClientID + 1;
theWM->allClients->append((void*)c);
return c;
}
void
removeClient(Client *c) {
if (c == 0)
return;
// Remove the client from our client list.
Node* cND = theWM->allClients->inList(c);
assert (cND != NULL);
theWM->allClients->remove(cND);
if (hidden(c))
unhidec(c, 0);
if (c == current)
current = 0;
if (c->parent != root)
XDestroyWindow(dpy, c->parent);
if (c->ncmapwins != 0) {
XFree(c->cmapwins);
free(c->wmcmaps);
}
cout << "Destroying client "<< c->clientID <<endl;
if (c->name != 0) {
cout << "Destroying client "<< c->clientID<<" name |"<<c->name<<"|"<<endl;
XFree(c->name);
c->name = 0;
}
if (c->fallback_name != 0) {
cout << "Destroying client "<< c->clientID<<" fallback_name |"<<c->fallback_name<<"|"<<endl;
// XFree(c->fallback_name);
delete c->fallback_name;
c->fallback_name = 0;
}
// free(c);
delete c;
c = NULL;
return;
}
void
WindowManager::positionExpose(void) {
char buf[4*2 + 3 +1];
Client* c = current;
sprintf(buf, "%i , %i", c->rX, c->rY - titleHeightc(c));
XDrawString(dpy, popup, size_gc,
(80 - XTextWidth(popup_font, buf, strlen(buf))) / 2,
popup_font->ascent + 1, buf, strlen(buf));
return;
}
void
WindowManager::sizeExpose(void) {
char buf[4*2 + 3 +1];
int width, height;
Client* c = current;
if (NULL != c) { // client did not die during the operation
width = c->rW - 2 * border;
height = c->rH - (2 * border);
// We report 80x24 for an xterm
// even when a scrollbar is present.
if (c->size.flags & (PMinSize|PBaseSize) && c->size.flags & PResizeInc) {
if (c->size.flags & PBaseSize) {
width -= c->size.base_width;
height -= c->size.base_height;
} else {
width -= c->size.min_width;
height -= c->size.min_height;
}
}
if (c->size.width_inc != 0)
width /= c->size.width_inc;
if (c->size.height_inc != 0)
height /= c->size.height_inc;
sprintf(buf, "%i x %i", width, height);
XDrawString(dpy, popup, size_gc,
(80 - XTextWidth(popup_font, buf, strlen(buf))) / 2,
popup_font->ascent + 1, buf, strlen(buf));
}
else { // client died during the operation. CYA
XUnmapWindow(dpy, popup);
mode = wmReady;
}
return;
}
void
closeClient(Client *c) {
if (c == 0)
return;
// Terminate things nicely if possible. Be brutal otherwise.
if (c->proto & Pdelete) {
sendcmessage(c->window, wm_protocols, wm_delete, CurrentTime);
} else {
XKillClient(dpy, c->window);
}
return;
}
void
setClientState(Client *c, int state) {
long data[2];
data[0] = (long) state;
data[1] = (long) None;
c->state = state;
XChangeProperty(dpy, c->window, wm_state, wm_state, 32, PropModeReplace,
(unsigned char *) data, 2);
}
static void
sendcmessage(Window w, Atom a, long data0, long data1) {
XEvent ev;
long mask;
memset(&ev, '\0', sizeof ev);
ev.xclient.type = ClientMessage;
ev.xclient.window = w;
ev.xclient.message_type = a;
ev.xclient.format = 32;
ev.xclient.data.l[0] = data0;
ev.xclient.data.l[1] = data1;
mask = (w == root) ? SubstructureRedirectMask : 0L;
XSendEvent(dpy, w, False, mask, &ev);
}
void
WindowManager::freeAllClients(void) {
Client *c;
Node *cND;
XWindowChanges wc;
cout << "Freeing " << theWM->allClients->length() << " clients"<<endl;
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
if (NULL == c) {
// if this client is NULL, we are in deep doo doo
cout << "Found a null client in the client list" << endl << flush;
// this was a pause before crashing
// sleepval.tv_sec = 0;
// sleepval.tv_usec = 1250000;
// cout << "About to sleep "<< (sleepval.tv_usec)/1000;
// cout << " millisec" << flush;
// select(0, 0, 0, 0, &sleepval);
// cout << " ... done sleeping" << endl << flush;
assert (NULL != c);
}
if (NULL != c->name) {
cout << "Moving client " << c->clientID << " named |" << c->name << endl;
}
else if (NULL != c->fallback_name) {
cout << "Moving client " << c->clientID << " fallback_named |" << c->fallback_name << endl;
}
else {
cout << "Moving NAMELESS client " << c->clientID<<endl<<flush;
}
innerSendClienttoWS(c, 1);
int not_mapped = !normal(c);
// Remap the window if it was hidden.
if (not_mapped) {
XMapWindow(dpy, c->parent);
XMapWindow(dpy, c->window);
c->isMapped = 1;
}
// Reparent it, and then push it to the bottom if it was hidden.
XReparentWindow(dpy, c->window, root,
c->size.x + border, c->size.y + border);
if (not_mapped)
XLowerWindow(dpy, c->window);
// Give it back its initial border width.
wc.border_width = c->border;
XConfigureWindow(dpy, c->window, CWBorderWidth, &wc);
}
return;
}
extern void
Client_ColorMap(XEvent *e) {
int i;
Client *c;
Node *cND;
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
// if this client is NULL, we are in deep doo doo
assert (NULL != c);
for (i = 0; i < c->ncmapwins; i++) {
if (c->cmapwins[i] == e->xcolormap.window) {
c->wmcmaps[i] = e->xcolormap.colormap;
if (c == current)
cmapfocus(c);
return;
}
}
}
return;
}
extern int
hidden(Client *c) {
if (c->state == IconicState)
return 1;
else
return 0;
}
extern int
withdrawn(Client *c) {
return c->state == WithdrawnState;
}
extern int
normal(Client *c) {
return c->state == NormalState;
}
// -------------------------------------------
// window manager manipulations of client appearance
void
WindowManager::backClient(Client *c) {
if (c == 0)
return;
XLowerWindow(dpy, c->window);
XLowerWindow(dpy, c->parent);
return;
}
void
WindowManager::raiseClient(Client *c) {
if (c == 0)
return;
// workSpace->topClient = c;
XMapRaised(dpy, c->parent);
XMapRaised(dpy, c->window);
c->isMapped = 1;
return;
}
void
WindowManager::drawDeadlyBox(Client *c) {
int quarter;
XSetForeground(dpy, theWM->gc_frame, theWM->boxColor.pixel);
quarter = (border + titleHeight()) / 4;
if (DBundrawn == c->boxStatus)
c->boxStatus = DBunarmed;
switch (c->boxStatus) {
case DBunarmed:
XDrawRectangle(dpy, c->parent, theWM->gc_frame,
quarter, quarter, 2 * quarter, 2 * quarter);
break;
case DBarmed:
// xfillrectangle is off by one from xdrawrectangle,
// and the line width in gc_frame is 2,
// so the offset in initial (x,y) is +1 - linewidth = -1
// and the total width is 2*quarter + linewidth
XFillRectangle(dpy, c->parent, theWM->gc_frame,
quarter-1, quarter-1, 2 * quarter + 2, 2 * quarter + 2);
break;
default:
// this should not happen
break;
}
return;
}
void
WindowManager::drawTitle(Client *c) {
int quarter;
quarter = (border + titleHeight()) / 4;
XSetForeground(dpy, theWM->gc_frame, theWM->titleColor.pixel);
if (c->name != 0)
XDrawString(dpy, c->parent, theWM->gc_frame, border + 3 * quarter,
font->ascent + font->descent, c->name, strlen(c->name));
return;
}
void
WindowManager::drawClientBorder(Client *c, int active) {
XSetWindowAttributes attr; // rely on initialization by system ....
if (c->parent == root || c->parent == 0)
return;
if (active) {
if ((0 == usePixmapsP) || (None == activeBgd))
XSetWindowBackground(dpy, c->parent, theWM->activeBorderColor.pixel);
else {
attr.background_pixmap = theWM->activeBgd;
XChangeWindowAttributes(dpy, c->parent, CWBackPixmap , &attr);
}
}
else { // inactive window
if ((0 == usePixmapsP) || (None == inactiveBgd)) {
XSetWindowBackground(dpy, c->parent, theWM->inactiveBorderColor.pixel);
}
else {
attr.background_pixmap = theWM->inactiveBgd;
XChangeWindowAttributes(dpy, c->parent, CWBackPixmap , &attr);
}
}
XClearWindow(dpy, c->parent);
// draw the thin outline between the client and its border
if (!active)
XDrawRectangle(dpy, c->parent, gc_thin, border - 1, border - 1,
c->size.width - 2 * border + 1, c->size.height - 2 * border + 1);
if (active && c->accepts_focus && c->name) {
drawDeadlyBox(c);
drawTitle(c);
}
// return to normal
return;
}
void WindowManager::drawClientOutline(Client* c) {
// use rX, rY, rW, rH, and title height
// cout << "draw client outline" << endl << flush;
assert (c->rW * c->rH > 0);
// GC gcTmp = gc;
// I find it much easier to use a bunch of mnemonic variables
// than to try to follow convoluted X calls. Any decent
// compiler will optimize them away, in any case.
// int w = c->size.width;
// int h = c->size.height;
// top left corner
int x1 = c->rX + 1; // xfillrectangle is off by one from xdrawrectangle!
int y1 = c->rY + 1; // xfillrectangle is off by one from xdrawrectangle!
// top right corner
int x2 = x1 + c->rW;
int y2 = y1;
// bottom left corner
// int x3 = x1;
int y3 = y1 + c->rH;
// bottom right corner
// int x4 = x1 + c->rW;
// int y4 = y1 + c->rH;
int tH = theWM->titleHeightc(c);
// coords of middle points
int xm, ym;
int i, N;
N = 3;
// draw the window with crossbars
for (i = 0 ; i <= N; i++) {
xm = x1 + ((i * (x2 - x1)) / N);
ym = y1 + ((i * (y3 - y1)) / N);
XDrawLine(dpy, root, gc, xm, y1, xm, y3);
XDrawLine(dpy, root, gc, x1, ym, x2, ym);
}
// outline the title bar, if any
if (tH > 0) {
XDrawLine(dpy, root, gc,
x1, y1,
x1, y1 - tH);
XDrawLine(dpy, root, gc,
x1, y1 - tH,
x2, y2 - tH);
XDrawLine(dpy, root, gc,
x2, y2,
x2, y2 - tH);
}
return;
}
// -------------------------------------------
// WIndow Manager resizing clients
void
WindowManager::startResizingClient(XButtonEvent *xbe, Client* c) {
Cursor cursor;
assert (wmResizing == mode);
raiseClient(c);
warpPointerToBorder(c);
c->gripEdge = whichEdge(c, xbe->x_root, xbe->y_root);
cursor = edgecursor(c->gripEdge);
// cout << "grip edge: "<<c->gripEdge << endl;
XGrabServer(dpy);
XChangeActivePointerGrab(dpy,
theWM->moving_event_mask,
cursor, CurrentTime);
c->sX = c->size.x;
c->sY = c->size.y;
c->sW = c->size.width;
c->sH = c->size.height;
c->sBX = xbe->x_root;
c->sBY = xbe->y_root;
c->rX = c->sX;
c->rY = c->sY;
c->rW = c->sW;
c->rH = c->sH;
c->rBX = c->sBX;
c->rBY = c->sBY;
// do NOT draw the first outline here: wait for a motion event
c->outlinedP = 0;
return;
}
void
WindowManager::motionNotifyResizing() {
assert (wmResizing == mode);
int dx, dy;
Client* c = current;
if (NULL != c) { // client did not die during the operation
if (1 == c->outlinedP) {
drawClientOutline(c); // erase the previous one
c->outlinedP = 0;
}
getMouse (&c->rBX, &c->rBY);
dx = c->rBX - c->sBX;
dy = c->rBY - c->sBY;
switch (c->gripEdge) {
case ETopLeft:
c->rX = c->sX + dx;
c->rY = c->sY + dy;
c->rW = c->sW - dx;
c->rH = c->sH - dy;
break;
case ETop:
c->rY = c->sY + dy;
c->rH = c->sH - dy;
break;
case ETopRight:
c->rY = c->sY + dy;
c->rW = c->sW + dx;
c->rH = c->sH - dy;
break;
case ELeft:
c->rX = c->sX + dx;
c->rW = c->sW - dx;
break;
case ERight:
c->rW = c->sW + dx;
break;
case EBottomLeft:
c->rX = c->sX + dx;
c->rW = c->sW - dx;
c->rH = c->sH + dy;
break;
case EBottom:
c->rH = c->sH + dy;
break;
case EBottomRight:
c->rH = c->sH + dy;
c->rW = c->sW + dx;
break;
default:
// this should not happen
break;
}
// enforce somewhat sane boundaries.
int ix, iy;
int th = theWM->titleHeightc(c);
c->rW = imax(6*border, c->rW);
c->rW = imax(c->size.min_width, c->rW);
if (c->size.width_inc > 1) {
ix = c->rW / c->size.width_inc;
c->rW = ix * c->size.width_inc;
}
else if (c->size.width_inc == 0)
c->rW = c->sW;
c->rH = imax(6*border, c->rH);
c->rH = imax(c->size.min_height, c->rH);
if (c->size.height_inc > 1) {
iy = c->rH / c->size.height_inc;
c->rH = iy * c->size.height_inc;
}
else if (c->size.height_inc == 0)
c->rH = c->sH;
if (1 == protectTopLeft) {
// ensure the top-left corner is on the screen
c->rX = imax(0 , c->rX);
c->rX = imin(c->rX, display_width - 2 * border);
c->rY = imax(th , c->rY);
c->rY = imin(c->rY, display_height - 2 * border);
}
// there is a slight bug in the above: it you keep trying to
// resize the top edge off the screen, it will sometimes bump
// the lower edge down by th
if (0 == c->outlinedP) {
drawClientOutline(c); // draw the next one
c->outlinedP = 1;
}
positionFeedbackWindow();
}
else { // client died during the operation. CYA.
XUnmapWindow(dpy, popup);
mode = wmReady;
}
return;
}
void
WindowManager::buttonReleaseResizing() {
assert (wmResizing == mode);
Client* c = current;
XUngrabServer(dpy);
// cout << "Finish resizing" << endl << flush;
int th = titleHeightc(c);
if (1 == c->outlinedP) {
drawClientOutline(c); // erase the last one
c->outlinedP = 0;
}
c->sX = c->rX;
c->sY = c->rY;
c->size.x = c->rX;
c->size.y = c->rY;
c->sW = c->rW;
c->sH = c->rH;
c->size.width = c->rW;
c->size.height = c->rH;
c->sBX = c->rBX;
c->sBY = c->rBY;
assert (c == current);
XMoveResizeWindow(dpy, c->parent,
c->sX, c->sY - th,
c->sW, c->sH + th);
sendConfigureNotify(c);
XMoveResizeWindow(dpy, c->window, border, border + th,
c->sW - 2 * border, c->sH - 2 * border);
XUnmapWindow(dpy, popup);
mode = wmReady;
return;
}
Edge
WindowManager::whichEdge(Client *c, int bx, int by) {
int sensWidth = 2*border;
int x = c->size.x;
int y = c->size.y;
int w = c->size.width;
int h = c->size.height;
int th = titleHeightc(c);
if ((abs (x - bx) <= sensWidth) && (abs ((y - th) - by) <= sensWidth + th))
return ETopLeft;
if ((abs (x - bx) <= sensWidth) && (abs ((y + h) - by) <= sensWidth))
return EBottomLeft;
if ((abs ((x+w) - bx) <= sensWidth) && (abs ((y - th) - by) <= sensWidth + th))
return ETopRight;
if ((abs ((x+w) - bx) <= sensWidth) && (abs ((y + h) - by) <= sensWidth))
return EBottomRight;
if (abs(x-bx) <= sensWidth)
return ELeft;
if (abs((y+h)-by) <= sensWidth)
return EBottom;
if (abs((x+w)-bx) <= sensWidth)
return ERight;
// the only remaining case!
return ETop;
}
// -------------------------------------------
// WIndow Manager moving clients around
void
WindowManager::startMovingClient(XEvent *xe, Client* c) {
assert (wmMoving == mode);
warpPointerToBorder(c);
Cursor cursor;
// start moving client
c->gripEdge = ENone;
cursor = edgecursor(c->gripEdge);
XGrabServer(dpy);
XChangeActivePointerGrab(dpy,
theWM->moving_event_mask,
cursor, CurrentTime);
if (c->size.width * c->size.height * 100 <= opaqueMoveSize * display_width * display_height)
c->opaqueMoveP = 1;
else
c->opaqueMoveP = 0;
c->sX = c->size.x;
c->sY = c->size.y;
c->sW = c->size.width;
c->sH = c->size.height;
getMouse ( &c->sBX, &c->sBY);
c->rX = c->sX;
c->rY = c->sY;
c->rW = c->sW;
c->rH = c->sH;
c->rBX = c->sBX;
c->rBY = c->sBY;
// do NOT draw the first outline here: wait for a motion event
return;
}
void
WindowManager::motionNotifyMoving() {
assert (mode == wmMoving);
int dx, dy;
int xT, yT;
Client* c = current;
// if the client just terminated itself during the move,
// the current client could be NULL. In that
// case, abort it and go to the ready state
if (NULL != c) {
getMouse ( &c->rBX, &c->rBY);
dx = c->rBX - c->sBX;
dy = c->rBY - c->sBY;
xT = c->sX + dx;
yT = c->sY + dy;
if (1 == protectTopLeft) {
// ensure the top-left corner is on the screen
// ensure the top-left corner is on the screen
xT = imax(0 , xT);
xT = imin(xT, display_width - 2 * border);
yT = imax(theWM->titleHeightc(c) , yT);
yT = imin(yT, display_height - 2 * border);
}
dx = xT - c->sX;
dy = yT - c->sY;
if (0 == c->opaqueMoveP) {
if (1 == c->outlinedP) {
theWM->drawClientOutline(c); // erase old one
c->outlinedP = 0;
}
c->rX = c->sX + dx;
c->rY = c->sY + dy;
if (0 == c->outlinedP) {
theWM->drawClientOutline(c); // draw the new one
c->outlinedP = 1;
}
}
else { // opaque moving
c->rX = c->sX + dx;
c->rY = c->sY + dy;
c->sX = c->rX;
c->sY = c->rY;
c->sBX = c->rBX;
c->sBY = c->rBY;
c->size.x = c->rX;
c->size.y = c->rY;
// actually move the client
XMoveWindow(dpy, c->parent,
c->size.x, c->size.y - titleHeightc(c));
sendConfigureNotify(c);
}
positionFeedbackWindow();
}
else { // client died during the operation. CYA.
XUnmapWindow(dpy, popup);
mode = wmReady;
}
return;
}
void
WindowManager::buttonReleaseMoving() {
Client* c = current;
// cout << "Stop moving" << endl << flush;
XUngrabServer(dpy);
if (0 == c->opaqueMoveP) {
if (1 == c->outlinedP) {
theWM->drawClientOutline(c); // erase last one
c->outlinedP = 0;
}
}
c->sX = c->rX;
c->sY = c->rY;
c->sBX = c->rBX;
c->sBY = c->rBY;
c->size.x = c->rX;
c->size.y = c->rY;
// actually move the client
XMoveWindow(dpy, c->parent,
c->size.x, c->size.y - titleHeightc(c));
sendConfigureNotify(c);
XUnmapWindow(dpy, popup);
mode = wmReady;
return;
}
void
WindowManager::positionFeedbackWindow() {
// int x, y;
Client* c = current;
// must use starting coords, to avoid unpleasant stray lines on the client
XMoveResizeWindow(dpy, popup, c->sX + c->sW/4, c->sY + c->sH/4,
80, popup_font->ascent + popup_font->descent + 1);
XMapRaised(dpy, popup);
// popup contents get redrawn. Eventually, the function
// positionExpose or sizeExpose will get called to do the actual redrawing.
XClearArea(dpy, popup, 0, 0, 0, 0, True);
return;
}
void
WindowManager::startKillingClient(XButtonEvent *xbe, Client* c) {
assert (wmKilling == mode);
XChangeActivePointerGrab(dpy,
theWM->moving_event_mask,
frame_cursor, CurrentTime);
c->boxStatus = DBarmed;
drawClientBorder(c, 1);
return;
}
void
WindowManager::motionNotifyKilling() {
assert (wmKilling == mode);
Client* c = current;
BoxStatus oldBS = c->boxStatus;
BoxStatus nuBS;
if (1 == mouseInDeadlyBox(c))
nuBS = DBarmed;
else
nuBS = DBunarmed;
if (oldBS != nuBS) {
c->boxStatus = nuBS;
drawClientBorder(c, 1);
}
return;
}
void
WindowManager::buttonReleaseKilling() {
assert (wmKilling == mode);
// if in the current clients deadly box, kill the current client
if (1 == mouseInDeadlyBox(current))
closeClient(current);
mode = wmReady;
return;
}
// -------------------------------------------
// end of client.cc
// -------------------------------------------
|