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.
27 #include "statusbar.h"
29 extern AwesomeConf globalconf
;
32 * \param screen Screen number
33 * \param statusbar statusbar
35 * \param padding Padding
38 get_screen_area(int screen
, Statusbar
*statusbar
, Padding
*padding
)
40 int screen_number
= 0;
41 XineramaScreenInfo
*si
;
44 if(XineramaIsActive(globalconf
.display
))
46 si
= XineramaQueryScreens(globalconf
.display
, &screen_number
);
47 if (screen_number
< screen
)
48 eprint("Info request for unknown screen.");
49 area
.x
= si
[screen
].x_org
;
50 area
.y
= si
[screen
].y_org
;
51 area
.width
= si
[screen
].width
;
52 area
.height
= si
[screen
].height
;
57 /* emulate Xinerama info but only fill the screen we want */
60 area
.width
= DisplayWidth(globalconf
.display
, screen
);
61 area
.height
= DisplayHeight(globalconf
.display
, screen
);
64 /* make padding corrections */
67 area
.x
+= padding
->left
;
68 area
.y
+= padding
->top
;
69 area
.width
-= padding
->left
+ padding
->right
;
70 area
.height
-= padding
->top
+ padding
->bottom
;
74 switch(statusbar
->position
)
77 area
.y
+= statusbar
->height
;
79 area
.height
-= statusbar
->height
;
82 area
.x
+= statusbar
->height
;
84 area
.width
-= statusbar
->height
;
92 * \param screen Screen number
93 * \param statusbar the statusbar
94 * \param padding Padding
98 get_display_area(int screen
, Statusbar
*statusbar
, Padding
*padding
)
103 area
.y
= statusbar
&& statusbar
->position
== BarTop
? statusbar
->height
: 0;
104 area
.width
= DisplayWidth(globalconf
.display
, screen
);
105 area
.height
= DisplayHeight(globalconf
.display
, screen
) -
107 (statusbar
->position
== BarTop
|| statusbar
->position
== BarBot
) ? statusbar
->height
: 0);
109 /* make padding corrections */
112 area
.x
+= padding
->left
;
113 area
.y
+= padding
->top
;
114 area
.width
-= padding
->left
+ padding
->right
;
115 area
.height
-= padding
->top
+ padding
->bottom
;
120 /** Return the Xinerama screen number where the coordinates belongs to
121 * \param x x coordinate of the window
122 * \param y y coordinate of the window
123 * \return screen number or DefaultScreen of disp on no match
126 get_screen_bycoord(int x
, int y
)
131 /* don't waste our time */
132 if(!XineramaIsActive(globalconf
.display
))
133 return DefaultScreen(globalconf
.display
);
136 for(i
= 0; i
< get_screen_count(); i
++)
138 area
= get_screen_area(i
, NULL
, NULL
);
139 if((x
< 0 || (x
>= area
.x
&& x
< area
.x
+ area
.width
))
140 && (y
< 0 || (y
>= area
.y
&& y
< area
.y
+ area
.height
)))
143 return DefaultScreen(globalconf
.display
);
146 /** Return the actual screen count
147 * \return the number of screen available
150 get_screen_count(void)
154 if(XineramaIsActive(globalconf
.display
))
155 XineramaQueryScreens(globalconf
.display
, &screen_number
);
157 return ScreenCount(globalconf
.display
);
159 return screen_number
;
162 /** This returns the real X screen number for a logical
163 * screen if Xinerama is active.
164 * \param screen the logical screen
165 * \return the X screen
168 get_phys_screen(int screen
)
170 if(XineramaIsActive(globalconf
.display
))
171 return DefaultScreen(globalconf
.display
);
175 /** Move a client to a virtual screen
176 * \param c the client
177 * \param new_screen The destinatiuon screen
178 * \param doresize set to True if we also move the client to the new x_org and
179 * y_org of the new screen
182 move_client_to_screen(Client
*c
, int new_screen
, Bool doresize
)
185 int old_screen
= c
->screen
;
188 for(tag
= globalconf
.screens
[old_screen
].tags
; tag
; tag
= tag
->next
)
189 untag_client(c
, tag
, old_screen
);
191 /* tag client with new screen tags */
192 tag_client_with_current_selected(c
);
194 c
->screen
= new_screen
;
196 if(doresize
&& old_screen
!= c
->screen
)
198 to
= get_screen_area(c
->screen
, NULL
, NULL
);
199 from
= get_screen_area(old_screen
, NULL
, NULL
);
201 /* compute new coords in new screen */
202 c
->rx
= (c
->rx
- from
.x
) + to
.x
;
203 c
->ry
= (c
->ry
- from
.y
) + to
.y
;
204 /* check that new coords are still in the screen */
207 if(c
->rh
> to
.height
)
209 if(c
->rx
+ c
->rw
>= to
.x
+ to
.width
)
210 c
->rx
= to
.x
+ to
.width
- c
->rw
- 2 * c
->border
;
211 if(c
->ry
+ c
->rh
>= to
.y
+ to
.height
)
212 c
->ry
= to
.y
+ to
.height
- c
->rh
- 2 * c
->border
;
214 client_resize(c
, c
->rx
, c
->ry
, c
->rw
, c
->rh
, True
, False
);
217 focus(c
, True
, c
->screen
);
219 /* redraw statusbar on all screens */
220 statusbar_draw(old_screen
);
221 statusbar_draw(new_screen
);
224 /** Move mouse pointer to x_org and y_xorg of specified screen
225 * \param screen screen number
228 move_mouse_pointer_to_screen(int screen
)
230 if(XineramaIsActive(globalconf
.display
))
232 Area area
= get_screen_area(screen
, NULL
, NULL
);
233 XWarpPointer(globalconf
.display
,
235 DefaultRootWindow(globalconf
.display
),
236 0, 0, 0, 0, area
.x
, area
.y
);
239 XWarpPointer(globalconf
.display
,
241 RootWindow(globalconf
.display
, screen
),
246 /** Switch focus to a specified screen
247 * \param screen Screen ID
248 * \param arg screen number
249 * \ingroup ui_callback
252 uicb_screen_focus(int screen
, char *arg
)
254 int new_screen
, numscreens
= get_screen_count();
255 Tag
**curtags
= get_current_tags(screen
);
258 new_screen
= compute_new_value_from_arg(arg
, screen
);
260 new_screen
= screen
+ 1;
263 new_screen
= numscreens
- 1;
264 if (new_screen
> (numscreens
- 1))
267 focus(focus_get_latest_client_for_tag(new_screen
, curtags
[0]),
272 move_mouse_pointer_to_screen(new_screen
);
275 /** Move client to a virtual screen (if Xinerama is active)
276 * \param screen Screen ID
277 * \param arg screen number
278 * \ingroup ui_callback
281 uicb_client_movetoscreen(int screen
__attribute__ ((unused
)), char *arg
)
283 int new_screen
, prev_screen
;
284 Client
*sel
= globalconf
.focus
->client
;
286 if(!sel
|| !XineramaIsActive(globalconf
.display
))
290 new_screen
= compute_new_value_from_arg(arg
, sel
->screen
);
292 new_screen
= sel
->screen
+ 1;
294 if(new_screen
>= get_screen_count())
296 else if(new_screen
< 0)
297 new_screen
= get_screen_count() - 1;
299 prev_screen
= sel
->screen
;
300 move_client_to_screen(sel
, new_screen
, True
);
301 move_mouse_pointer_to_screen(new_screen
);
302 arrange(prev_screen
);
305 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80