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.
29 #include "statusbar.h"
30 #include "layouts/floating.h"
32 extern AwesomeConf globalconf
;
34 /** Move client with mouse
35 * \param screen Screen ID
37 * \ingroup ui_callback
40 uicb_client_movemouse(int screen
, char *arg
__attribute__ ((unused
)))
42 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
47 Client
*c
= globalconf
.focus
->client
;
48 Tag
**curtags
= get_current_tags(screen
);
53 if((curtags
[0]->layout
->arrange
!= layout_floating
)
55 uicb_client_togglefloating(screen
, NULL
);
61 area
= get_screen_area(c
->screen
,
62 globalconf
.screens
[screen
].statusbar
,
63 &globalconf
.screens
[screen
].padding
);
67 if(XGrabPointer(globalconf
.display
,
68 RootWindow(globalconf
.display
, c
->phys_screen
),
69 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
70 None
, globalconf
.cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
72 XQueryPointer(globalconf
.display
,
73 RootWindow(globalconf
.display
, c
->phys_screen
),
74 &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
76 statusbar_draw(c
->screen
);
79 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
83 XUngrabPointer(globalconf
.display
, CurrentTime
);
85 case ConfigureRequest
:
86 handle_event_configurerequest(&ev
);
89 handle_event_expose(&ev
);
92 handle_event_maprequest(&ev
);
95 nx
= ocx
+ (ev
.xmotion
.x
- x1
);
96 ny
= ocy
+ (ev
.xmotion
.y
- y1
);
97 if(abs(nx
) < globalconf
.screens
[screen
].snap
+ area
.x
&& nx
> area
.x
)
99 else if(abs((area
.x
+ area
.width
) - (nx
+ c
->w
+ 2 * c
->border
)) < globalconf
.screens
[screen
].snap
)
100 nx
= area
.x
+ area
.width
- c
->w
- 2 * c
->border
;
101 if(abs(ny
) < globalconf
.screens
[screen
].snap
+ area
.y
&& ny
> area
.y
)
103 else if(abs((area
.y
+ area
.height
) - (ny
+ c
->h
+ 2 * c
->border
)) < globalconf
.screens
[screen
].snap
)
104 ny
= area
.y
+ area
.height
- c
->h
- 2 * c
->border
;
105 client_resize(c
, nx
, ny
, c
->w
, c
->h
, False
, False
);
111 /** Resize client with mouse
112 * \param screen Screen ID
114 * \ingroup ui_callback
117 uicb_client_resizemouse(int screen
, char *arg
__attribute__ ((unused
)))
119 int ocx
, ocy
, nw
, nh
;
121 Client
*c
= globalconf
.focus
->client
;
122 Tag
**curtags
= get_current_tags(screen
);
127 if((curtags
[0]->layout
->arrange
!= layout_floating
)
129 uicb_client_togglefloating(screen
, NULL
);
137 if(XGrabPointer(globalconf
.display
, RootWindow(globalconf
.display
, c
->phys_screen
),
138 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
139 None
, globalconf
.cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
142 statusbar_draw(c
->screen
);
143 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
146 XMaskEvent(globalconf
.display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
150 XWarpPointer(globalconf
.display
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
151 XUngrabPointer(globalconf
.display
, CurrentTime
);
152 while(XCheckMaskEvent(globalconf
.display
, EnterWindowMask
, &ev
));
154 case ConfigureRequest
:
155 handle_event_configurerequest(&ev
);
158 handle_event_expose(&ev
);
161 handle_event_maprequest(&ev
);
164 if((nw
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
166 if((nh
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
168 client_resize(c
, c
->x
, c
->y
, nw
, nh
, True
, False
);
175 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80