2 * screen.c - screen management
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 <X11/extensions/Xinerama.h>
28 #include "statusbar.h"
31 extern AwesomeConf globalconf
;
34 * \param screen Screen number
35 * \param statusbar statusbar
36 * \param padding Padding
40 get_screen_area(int screen
, Statusbar
*statusbar
, Padding
*padding
)
42 int screen_number
= 0;
43 XineramaScreenInfo
*si
;
47 if(XineramaIsActive(globalconf
.display
))
49 si
= XineramaQueryScreens(globalconf
.display
, &screen_number
);
50 if (screen_number
< screen
)
51 eprint("Info request for unknown screen.");
52 area
.x
= si
[screen
].x_org
;
53 area
.y
= si
[screen
].y_org
;
54 area
.width
= si
[screen
].width
;
55 area
.height
= si
[screen
].height
;
60 /* emulate Xinerama info but only fill the screen we want */
63 area
.width
= DisplayWidth(globalconf
.display
, screen
);
64 area
.height
= DisplayHeight(globalconf
.display
, screen
);
67 /* make padding corrections */
70 area
.x
+= padding
->left
;
71 area
.y
+= padding
->top
;
72 area
.width
-= padding
->left
+ padding
->right
;
73 area
.height
-= padding
->top
+ padding
->bottom
;
76 for(sb
= statusbar
; sb
; sb
= sb
->next
)
82 area
.height
-= sb
->height
;
87 area
.width
-= sb
->height
;
97 * \param screen Screen number
98 * \param statusbar the statusbar
99 * \param padding Padding
103 get_display_area(int screen
, Statusbar
*statusbar
, Padding
*padding
)
110 area
.width
= DisplayWidth(globalconf
.display
, screen
);
111 area
.height
= DisplayHeight(globalconf
.display
, screen
);
113 for(sb
= statusbar
; sb
; sb
= sb
->next
)
115 area
.y
+= sb
->position
== Top
? sb
->height
: 0;
116 area
.height
-= (sb
->position
== Top
|| sb
->position
== Bottom
) ? sb
->height
: 0;
119 /* make padding corrections */
122 area
.x
+= padding
->left
;
123 area
.y
+= padding
->top
;
124 area
.width
-= padding
->left
+ padding
->right
;
125 area
.height
-= padding
->top
+ padding
->bottom
;
130 /** Return the Xinerama screen number where the coordinates belongs to
131 * \param x x coordinate of the window
132 * \param y y coordinate of the window
133 * \return screen number or DefaultScreen of disp on no match
136 get_screen_bycoord(int x
, int y
)
141 /* don't waste our time */
142 if(!XineramaIsActive(globalconf
.display
))
143 return DefaultScreen(globalconf
.display
);
146 for(i
= 0; i
< get_screen_count(); i
++)
148 area
= get_screen_area(i
, NULL
, NULL
);
149 if((x
< 0 || (x
>= area
.x
&& x
< area
.x
+ area
.width
))
150 && (y
< 0 || (y
>= area
.y
&& y
< area
.y
+ area
.height
)))
153 return DefaultScreen(globalconf
.display
);
156 /** Return the actual screen count
157 * \return the number of screen available
160 get_screen_count(void)
164 if(XineramaIsActive(globalconf
.display
))
165 XineramaQueryScreens(globalconf
.display
, &screen_number
);
167 return ScreenCount(globalconf
.display
);
169 return screen_number
;
172 /** This returns the real X screen number for a logical
173 * screen if Xinerama is active.
174 * \param screen the logical screen
175 * \return the X screen
178 get_phys_screen(int screen
)
180 if(XineramaIsActive(globalconf
.display
))
181 return DefaultScreen(globalconf
.display
);
185 /** Move a client to a virtual screen
186 * \param c the client
187 * \param new_screen The destinatiuon screen
188 * \param doresize set to True if we also move the client to the new x and
189 * y of the new screen
192 move_client_to_screen(Client
*c
, int new_screen
, Bool doresize
)
195 int old_screen
= c
->screen
;
198 for(tag
= globalconf
.screens
[old_screen
].tags
; tag
; tag
= tag
->next
)
199 untag_client(c
, tag
);
201 c
->screen
= new_screen
;
203 /* tag client with new screen tags */
204 tag_client_with_current_selected(c
);
206 if(doresize
&& old_screen
!= c
->screen
)
208 to
= get_screen_area(c
->screen
, NULL
, NULL
);
209 from
= get_screen_area(old_screen
, NULL
, NULL
);
211 /* compute new coords in new screen */
212 c
->rx
= (c
->rx
- from
.x
) + to
.x
;
213 c
->ry
= (c
->ry
- from
.y
) + to
.y
;
214 /* check that new coords are still in the screen */
217 if(c
->rh
> to
.height
)
219 if(c
->rx
+ c
->rw
>= to
.x
+ to
.width
)
220 c
->rx
= to
.x
+ to
.width
- c
->rw
- 2 * c
->border
;
221 if(c
->ry
+ c
->rh
>= to
.y
+ to
.height
)
222 c
->ry
= to
.y
+ to
.height
- c
->rh
- 2 * c
->border
;
224 client_resize(c
, c
->rx
, c
->ry
, c
->rw
, c
->rh
, True
, False
);
227 focus(c
, True
, c
->screen
);
229 /* redraw statusbar on all screens */
230 statusbar_draw_all(old_screen
);
231 statusbar_draw_all(new_screen
);
234 /** Move mouse pointer to x_org and y_xorg of specified screen
235 * \param screen screen number
238 move_mouse_pointer_to_screen(int screen
)
240 if(XineramaIsActive(globalconf
.display
))
242 Area area
= get_screen_area(screen
, NULL
, NULL
);
243 XWarpPointer(globalconf
.display
,
245 DefaultRootWindow(globalconf
.display
),
246 0, 0, 0, 0, area
.x
, area
.y
);
249 XWarpPointer(globalconf
.display
,
251 RootWindow(globalconf
.display
, screen
),
256 /** Switch focus to a specified screen
257 * \param screen Screen ID
258 * \param arg screen number
259 * \ingroup ui_callback
262 uicb_screen_focus(int screen
, char *arg
)
264 int new_screen
, numscreens
= get_screen_count();
267 new_screen
= compute_new_value_from_arg(arg
, screen
);
269 new_screen
= screen
+ 1;
272 new_screen
= numscreens
- 1;
273 if (new_screen
> (numscreens
- 1))
276 focus(focus_get_current_client(new_screen
), True
, new_screen
);
278 move_mouse_pointer_to_screen(new_screen
);
281 /** Move client to a virtual screen (if Xinerama is active)
282 * \param screen Screen ID
283 * \param arg screen number
284 * \ingroup ui_callback
287 uicb_client_movetoscreen(int screen
__attribute__ ((unused
)), char *arg
)
289 int new_screen
, prev_screen
;
290 Client
*sel
= globalconf
.focus
->client
;
292 if(!sel
|| !XineramaIsActive(globalconf
.display
))
296 new_screen
= compute_new_value_from_arg(arg
, sel
->screen
);
298 new_screen
= sel
->screen
+ 1;
300 if(new_screen
>= get_screen_count())
302 else if(new_screen
< 0)
303 new_screen
= get_screen_count() - 1;
305 prev_screen
= sel
->screen
;
306 move_client_to_screen(sel
, new_screen
, True
);
307 move_mouse_pointer_to_screen(new_screen
);
308 arrange(prev_screen
);
311 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80