rename uicb_*mouse to uicb_client_*mouse
[awesome.git] / mouse.c
blob20c948ab1747b909bbb9091b5cb500bfb9b17315
1 /*
2 * mouse.c - mouse managing
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "mouse.h"
23 #include "screen.h"
24 #include "layout.h"
25 #include "tag.h"
26 #include "util.h"
27 #include "event.h"
28 #include "window.h"
29 #include "layouts/floating.h"
31 void
32 uicb_client_movemouse(awesome_config *awesomeconf, const char *arg __attribute__ ((unused)))
34 int x1, y1, ocx, ocy, di, nx, ny;
35 unsigned int dui;
36 Window dummy;
37 XEvent ev;
38 ScreenInfo *si;
39 Client *c = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
41 if(!c)
42 return;
44 if((get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange != layout_floating)
45 && !c->isfloating)
46 uicb_client_togglefloating(awesomeconf, "DUMMY");
47 else
48 restack(awesomeconf);
50 si = get_screen_info(c->display, c->screen, &awesomeconf->statusbar);
52 ocx = nx = c->x;
53 ocy = ny = c->y;
54 if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen), False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
55 None, awesomeconf->cursor[CurMove], CurrentTime) != GrabSuccess)
56 return;
57 XQueryPointer(c->display, RootWindow(c->display, c->phys_screen), &dummy, &dummy, &x1, &y1, &di, &di, &dui);
58 for(;;)
60 XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
61 switch (ev.type)
63 case ButtonRelease:
64 XUngrabPointer(c->display, CurrentTime);
65 p_delete(&si);
66 return;
67 case ConfigureRequest:
68 handle_event_configurerequest(&ev, &awesomeconf[0 - awesomeconf->screen]);
69 break;
70 case Expose:
71 handle_event_expose(&ev, &awesomeconf[0 - awesomeconf->screen]);
72 break;
73 case MapRequest:
74 handle_event_maprequest(&ev, &awesomeconf[0 - awesomeconf->screen]);
75 break;
76 case MotionNotify:
77 XSync(c->display, False);
78 nx = ocx + (ev.xmotion.x - x1);
79 ny = ocy + (ev.xmotion.y - y1);
80 if(abs(nx) < awesomeconf->snap + si[c->screen].x_org && nx > si[c->screen].x_org)
81 nx = si[c->screen].x_org;
82 else if(abs((si[c->screen].x_org + si[c->screen].width) - (nx + c->w + 2 * c->border)) < awesomeconf->snap)
83 nx = si[c->screen].x_org + si[c->screen].width - c->w - 2 * c->border;
84 if(abs(ny) < awesomeconf->snap + si[c->screen].y_org && ny > si[c->screen].y_org)
85 ny = si[c->screen].y_org;
86 else if(abs((si[c->screen].y_org + si[c->screen].height) - (ny + c->h + 2 * c->border)) < awesomeconf->snap)
87 ny = si[c->screen].y_org + si[c->screen].height - c->h - 2 * c->border;
88 client_resize(c, nx, ny, c->w, c->h, awesomeconf, False, False);
89 break;
94 void
95 uicb_client_resizemouse(awesome_config *awesomeconf, const char *arg __attribute__ ((unused)))
97 int ocx, ocy, nw, nh;
98 XEvent ev;
99 Client *c = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel;
101 if(!c)
102 return;
104 if((get_current_layout(awesomeconf->tags, awesomeconf->ntags)->arrange != layout_floating)
105 && !c->isfloating)
106 uicb_client_togglefloating(awesomeconf, "DUMMY");
107 else
108 restack(awesomeconf);
110 ocx = c->x;
111 ocy = c->y;
112 if(XGrabPointer(c->display, RootWindow(c->display, c->phys_screen),
113 False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
114 None, awesomeconf->cursor[CurResize], CurrentTime) != GrabSuccess)
115 return;
116 c->ismax = False;
117 XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
118 for(;;)
120 XMaskEvent(c->display, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
121 switch (ev.type)
123 case ButtonRelease:
124 XWarpPointer(c->display, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
125 XUngrabPointer(c->display, CurrentTime);
126 while(XCheckMaskEvent(c->display, EnterWindowMask, &ev));
127 return;
128 case ConfigureRequest:
129 handle_event_configurerequest(&ev, &awesomeconf[0 - awesomeconf->screen]);
130 break;
131 case Expose:
132 handle_event_expose(&ev, &awesomeconf[0 - awesomeconf->screen]);
133 break;
134 case MapRequest:
135 handle_event_maprequest(&ev, &awesomeconf[0 - awesomeconf->screen]);
136 break;
137 case MotionNotify:
138 XSync(c->display, False);
139 if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
140 nw = 1;
141 if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
142 nh = 1;
143 client_resize(c, c->x, c->y, nw, nh, awesomeconf, True, False);
144 break;
150 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99