add common.h to dist target
[awesome.git] / screen.c
blob950cfe9583ed98256cc35dc3605c77b6ee30a343
1 /*
2 * screen.c - screen management
3 *
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 *
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 "util.h"
23 #include "client.h"
24 #include "screen.h"
25 #include "tag.h"
26 #include "layout.h"
28 extern Client *sel, *clients;
30 /** Get screens info
31 * \param disp Display ref
32 * \param screen Screen number
33 * \param statusbar statusbar
34 * \param screen_number int pointer filled with number of screens
35 * \return ScreenInfo struct array with all screens info
37 ScreenInfo *
38 get_screen_info(Display *disp, int screen, Statusbar statusbar, int *screen_number)
40 int i, fake_screen_number = 0;
41 ScreenInfo *si;
43 if(XineramaIsActive(disp))
45 si = XineramaQueryScreens(disp, screen_number);
46 fake_screen_number = *screen_number;
48 else
50 /* emulate Xinerama info but only fill the screen we want */
51 *screen_number = 1;
52 si = p_new(ScreenInfo, screen + 1);
53 si[screen].width = DisplayWidth(disp, screen);
54 si[screen].height = DisplayHeight(disp, screen);
55 si[screen].x_org = 0;
56 si[screen].y_org = 0;
57 fake_screen_number = screen + 1;
60 for(i = 0; i < fake_screen_number; i++)
62 if(statusbar.position == BarTop
63 || statusbar.position == BarBot)
64 si[i].height -= statusbar.height;
65 if(statusbar.position == BarTop)
66 si[i].y_org += statusbar.height;
69 return si;
72 /** Get display info
73 * \param disp Display ref
74 * \param screen Screen number
75 * \param statusbar the statusbar
76 * \return ScreenInfo struct pointer with all display info
78 ScreenInfo *
79 get_display_info(Display *disp, int screen, Statusbar statusbar)
81 ScreenInfo *si;
83 si = p_new(ScreenInfo, 1);
85 si->x_org = 0;
86 si->y_org = statusbar.position == BarTop ? statusbar.height : 0;
87 si->width = DisplayWidth(disp, screen);
88 si->height = DisplayHeight(disp, screen) -
89 ((statusbar.position == BarTop || statusbar.position == BarBot) ? statusbar.height : 0);
91 return si;
94 void
95 uicb_focusnextscreen(Display *disp,
96 DC *drawcontext,
97 awesome_config * awesomeconf,
98 const char *arg __attribute__ ((unused)))
100 Client *c;
101 int next_screen = awesomeconf->screen + 1 >= ScreenCount(disp) ? 0 : awesomeconf->screen + 1;
103 for(c = clients; c && !isvisible(c, next_screen, awesomeconf[next_screen - awesomeconf->screen].tags, awesomeconf[next_screen - awesomeconf->screen].ntags); c = c->next);
104 if(c)
106 focus(c->display, &drawcontext[next_screen - awesomeconf->screen], c, True, &awesomeconf[next_screen - awesomeconf->screen]);
107 restack(c->display, &drawcontext[next_screen - awesomeconf->screen], &awesomeconf[next_screen - awesomeconf->screen]);
111 void
112 uicb_focusprevscreen(Display *disp,
113 DC *drawcontext,
114 awesome_config * awesomeconf,
115 const char *arg __attribute__ ((unused)))
117 Client *c;
118 int prev_screen = awesomeconf->screen - 1 < 0 ? ScreenCount(disp) - 1 : awesomeconf->screen - 1;
120 for(c = clients; c && !isvisible(c, prev_screen, awesomeconf[prev_screen - awesomeconf->screen].tags, awesomeconf[prev_screen - awesomeconf->screen].ntags); c = c->next);
121 if(c)
123 focus(c->display, &drawcontext[prev_screen - awesomeconf->screen], c, True, &awesomeconf[prev_screen - awesomeconf->screen]);
124 restack(c->display, &drawcontext[prev_screen - awesomeconf->screen], &awesomeconf[prev_screen - awesomeconf->screen]);