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 "layouts/floating.h"
32 uicb_client_movemouse(awesome_config
*awesomeconf
, const char *arg
__attribute__ ((unused
)))
34 int x1
, y1
, ocx
, ocy
, di
, nx
, ny
;
39 Client
*c
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
44 if((get_current_layout(awesomeconf
->tags
, awesomeconf
->ntags
)->arrange
!= layout_floating
)
46 uicb_client_togglefloating(awesomeconf
, "DUMMY");
50 si
= get_screen_info(c
->display
, c
->screen
, &awesomeconf
->statusbar
);
54 if(XGrabPointer(c
->display
, RootWindow(c
->display
, c
->phys_screen
), False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
55 None
, awesomeconf
->cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
57 XQueryPointer(c
->display
, RootWindow(c
->display
, c
->phys_screen
), &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
60 XMaskEvent(c
->display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
64 XUngrabPointer(c
->display
, CurrentTime
);
67 case ConfigureRequest
:
68 handle_event_configurerequest(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
71 handle_event_expose(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
74 handle_event_maprequest(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
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
);
95 uicb_client_resizemouse(awesome_config
*awesomeconf
, const char *arg
__attribute__ ((unused
)))
99 Client
*c
= get_current_tag(awesomeconf
->tags
, awesomeconf
->ntags
)->client_sel
;
104 if((get_current_layout(awesomeconf
->tags
, awesomeconf
->ntags
)->arrange
!= layout_floating
)
106 uicb_client_togglefloating(awesomeconf
, "DUMMY");
108 restack(awesomeconf
);
112 if(XGrabPointer(c
->display
, RootWindow(c
->display
, c
->phys_screen
),
113 False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
114 None
, awesomeconf
->cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
117 XWarpPointer(c
->display
, None
, c
->win
, 0, 0, 0, 0, c
->w
+ c
->border
- 1, c
->h
+ c
->border
- 1);
120 XMaskEvent(c
->display
, MOUSEMASK
| ExposureMask
| SubstructureRedirectMask
, &ev
);
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
));
128 case ConfigureRequest
:
129 handle_event_configurerequest(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
132 handle_event_expose(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
135 handle_event_maprequest(&ev
, &awesomeconf
[0 - awesomeconf
->screen
]);
138 XSync(c
->display
, False
);
139 if((nw
= ev
.xmotion
.x
- ocx
- 2 * c
->border
+ 1) <= 0)
141 if((nh
= ev
.xmotion
.y
- ocy
- 2 * c
->border
+ 1) <= 0)
143 client_resize(c
, c
->x
, c
->y
, nw
, nh
, awesomeconf
, True
, False
);
150 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99