Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <X11/X.h>
- #include <X11/Xlib.h>
- int main ()
- {
- Display* d = XOpenDisplay(0);
- Window w = XCreateSimpleWindow (d, RootWindow(d, 0), 300, 300, 300, 300, 0,
- BlackPixel (d, 0), BlackPixel(d, 0));
- XMapWindow(d, w);
- XMoveResizeWindow(d, w, 300, 300, 300, 300);
- XSelectInput (d, w, ButtonPressMask|ButtonReleaseMask|PointerMotionMask);
- printf ("Display %x Window %x\n", d, (void*)w);
- int dragging=0;
- int ptr_x, ptr_y;
- int win_x = 300, win_y = 300;
- int win_h = 300, win_w = 300;
- int win_new_x, win_new_y;
- int win_new_h, win_new_w;
- int ptr_new_x, ptr_new_y;
- XWindowAttributes attr;
- Window child;
- while (1)
- {
- XEvent xev;
- XNextEvent(d, &xev);
- switch (xev.type)
- {
- case ButtonPress:
- printf ("Dragging!\n");
- dragging = 1;
- ptr_x = xev.xbutton.x;
- ptr_y = xev.xbutton.y;
- XGetWindowAttributes (d, w, &attr);
- XTranslateCoordinates(d, w, RootWindow(d, 0), 0, 0, &win_x, &win_y, &child);
- XTranslateCoordinates(d, w, RootWindow(d, 0), xev.xbutton.x, xev.xbutton.y, &ptr_x, &ptr_y, &child);
- win_w = attr.width;
- win_h = attr.height;
- printf ("Starting with x=%d y=%d w=%d h=%d\n", win_x, win_y, win_w, win_h);
- break;
- case ButtonRelease:
- printf ("Not Dragging!\n");
- dragging = 0;
- break;
- case MotionNotify:
- if (dragging)
- {
- int dx, dy;
- XTranslateCoordinates(d, w, RootWindow(d, 0), xev.xmotion.x, xev.xmotion.y, &ptr_new_x, &ptr_new_y, &child);
- dx = ptr_new_x - ptr_x;
- dy = ptr_new_y - ptr_y;
- printf ("dx = %d dy = %d\n", dx, dy);
- win_new_h = win_h - dy;
- win_new_w = win_w - dx;
- if (win_new_h < 100) win_new_h = 100;
- if (win_new_w < 100) win_new_w = 100;
- win_new_y = win_y + (win_h - win_new_h);
- win_new_x = win_x + (win_w - win_new_w);
- XMoveResizeWindow(d, w, win_new_x, win_new_y, win_new_w, win_new_h);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement