init: Add init.c
This commit is contained in:
@@ -27,6 +27,7 @@ project(${PROJECT_NAME} C)
|
|||||||
|
|
||||||
# Definition of the wmfs source
|
# Definition of the wmfs source
|
||||||
set(wmfs_src
|
set(wmfs_src
|
||||||
|
src/init.c
|
||||||
src/wmfs.c
|
src/wmfs.c
|
||||||
src/config.c
|
src/config.c
|
||||||
src/event.c
|
src/event.c
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ void
|
|||||||
client_hide(Client *c)
|
client_hide(Client *c)
|
||||||
{
|
{
|
||||||
client_unmap(c);
|
client_unmap(c);
|
||||||
|
c->hide = True;
|
||||||
setwinstate(c->win, IconicState);
|
setwinstate(c->win, IconicState);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -432,6 +433,7 @@ void
|
|||||||
client_unhide(Client *c)
|
client_unhide(Client *c)
|
||||||
{
|
{
|
||||||
client_map(c);
|
client_map(c);
|
||||||
|
c->hide = False;
|
||||||
setwinstate(c->win, NormalState);
|
setwinstate(c->win, NormalState);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -511,7 +511,9 @@ init_conf(void)
|
|||||||
if(j != i && strcmp(conf.tag[i].name, conf.tag[j].name) == 0)
|
if(j != i && strcmp(conf.tag[i].name, conf.tag[j].name) == 0)
|
||||||
fprintf(stderr, "WMFS Configuration: Warning! "
|
fprintf(stderr, "WMFS Configuration: Warning! "
|
||||||
"tag \"%s\" is already defined\n", conf.tag[j].name);
|
"tag \"%s\" is already defined\n", conf.tag[j].name);
|
||||||
|
seltag = 1;
|
||||||
|
for(i = 0; i < conf.ntag; ++i)
|
||||||
|
tags[i + 1] = conf.tag[i];
|
||||||
|
|
||||||
/* keybind */
|
/* keybind */
|
||||||
conf.nkeybind = cfg_size(cfg_keys, "key");
|
conf.nkeybind = cfg_size(cfg_keys, "key");
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ draw_text(Drawable d, int x, int y, char* fg, uint bg, int pad, char *str)
|
|||||||
DefaultColormap(dpy, screen), fg, &xftcolor);
|
DefaultColormap(dpy, screen), fg, &xftcolor);
|
||||||
|
|
||||||
/* Draw the text */
|
/* Draw the text */
|
||||||
XftDrawStringUtf8(xftd, &xftcolor, xftfont, x, y, (FcChar8 *)str, strlen(str));
|
XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)str, strlen(str));
|
||||||
|
|
||||||
/* Free the text color and XftDraw */
|
/* Free the text color and XftDraw */
|
||||||
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
|
XftColorFree(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &xftcolor);
|
||||||
@@ -78,7 +78,7 @@ textw(const char *text)
|
|||||||
if(!text)
|
if(!text)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
XftTextExtentsUtf8(dpy, xftfont, (FcChar8 *)text, strlen(text), &gl);
|
XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl);
|
||||||
|
|
||||||
return gl.width + xftfont->descent;
|
return gl.width + font->descent;
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/event.c
44
src/event.c
@@ -136,7 +136,7 @@ configurerequest(XEvent ev)
|
|||||||
XConfigureWindow(dpy, ev.xconfigurerequest.window,
|
XConfigureWindow(dpy, ev.xconfigurerequest.window,
|
||||||
ev.xconfigurerequest.value_mask, &wc);
|
ev.xconfigurerequest.value_mask, &wc);
|
||||||
if((c = client_get(ev.xconfigurerequest.window)))
|
if((c = client_get(ev.xconfigurerequest.window)))
|
||||||
if(wc.y < mw && wc.x < mh)
|
if(wc.y < MAXW && wc.x < MAXH)
|
||||||
client_moveresize(c, geo, True);
|
client_moveresize(c, geo, True);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -202,29 +202,23 @@ focusin(XEvent ev)
|
|||||||
void
|
void
|
||||||
grabbuttons(Client *c, Bool focused)
|
grabbuttons(Client *c, Bool focused)
|
||||||
{
|
{
|
||||||
|
int i, j;
|
||||||
uint mod = conf.client.mod;
|
uint mod = conf.client.mod;
|
||||||
|
uint bl[] = {Button1, Button2, Button3, Button4, Button5};
|
||||||
|
uint ml[] = {mod, mod|LockMask, mod|numlockmask, mod|scrolllockmask,
|
||||||
|
mod|numlockmask|scrolllockmask, mod|LockMask|scrolllockmask,
|
||||||
|
mod|LockMask|numlockmask,mod|LockMask|numlockmask|scrolllockmask};
|
||||||
|
|
||||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||||
|
|
||||||
if(focused)
|
if(focused)
|
||||||
{
|
for(i = 0; i < (sizeof bl / sizeof bl[0]); ++i)
|
||||||
XGrabButton(dpy, Button1, mod, c->win, False, ButtonMask, GrabModeAsync,GrabModeSync, None, None);
|
for(j = 0; j < (sizeof ml / sizeof ml[0]); ++j)
|
||||||
XGrabButton(dpy, Button1, mod|LockMask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
XGrabButton(dpy, bl[i], ml[j], c->win, False,
|
||||||
XGrabButton(dpy, Button1, mod|numlockmask, c->win, False, ButtonMask, GrabModeAsync,GrabModeSync, None, None);
|
ButtonMask, GrabModeAsync,GrabModeSync, None, None);
|
||||||
XGrabButton(dpy, Button1, mod|LockMask|numlockmask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
|
|
||||||
XGrabButton(dpy, Button2, mod, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button2, mod|LockMask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button2, mod|numlockmask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button2, mod|LockMask|numlockmask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
|
|
||||||
XGrabButton(dpy, Button3, mod, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button3, mod|LockMask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button3, mod|numlockmask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
XGrabButton(dpy, Button3, mod|LockMask|numlockmask, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
|
||||||
|
ButtonMask, GrabModeAsync, GrabModeSync, None, None);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -232,17 +226,17 @@ grabbuttons(Client *c, Bool focused)
|
|||||||
void
|
void
|
||||||
grabkeys(void)
|
grabkeys(void)
|
||||||
{
|
{
|
||||||
uint i;
|
uint i, j;
|
||||||
KeyCode code;
|
KeyCode code;
|
||||||
|
uint ml[] = {LockMask, numlockmask, scrolllockmask, numlockmask|scrolllockmask,
|
||||||
|
LockMask|scrolllockmask, LockMask|numlockmask, LockMask|numlockmask|scrolllockmask};
|
||||||
|
|
||||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||||
for(i = 0; i < conf.nkeybind; ++i)
|
for(i = 0; i < conf.nkeybind; ++i)
|
||||||
{
|
{
|
||||||
code = XKeysymToKeycode(dpy, keys[i].keysym);
|
code = XKeysymToKeycode(dpy, keys[i].keysym);
|
||||||
XGrabKey(dpy, code, keys[i].mod, root, True, GrabModeAsync, GrabModeAsync);
|
for(j = 0; j < (sizeof ml / sizeof ml[0]); ++j)
|
||||||
XGrabKey(dpy, code, keys[i].mod|numlockmask, root, True, GrabModeAsync, GrabModeAsync);
|
XGrabKey(dpy, code, keys[i].mod|ml[j], root, True, GrabModeAsync, GrabModeAsync);
|
||||||
XGrabKey(dpy, code, keys[i].mod|LockMask, root, True, GrabModeAsync, GrabModeAsync);
|
|
||||||
XGrabKey(dpy, code, keys[i].mod|LockMask|numlockmask, root, True, GrabModeAsync, GrabModeAsync);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -277,7 +271,6 @@ mapnotify(XEvent ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* MAPREQUEST */
|
/* MAPREQUEST */
|
||||||
void
|
void
|
||||||
maprequest(XEvent ev)
|
maprequest(XEvent ev)
|
||||||
@@ -311,7 +304,7 @@ mouseaction(Client *c, int x, int y, int type)
|
|||||||
ocx = c->geo.x;
|
ocx = c->geo.x;
|
||||||
ocy = c->geo.y;
|
ocy = c->geo.y;
|
||||||
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
||||||
None, cursor[((type) ?CurResize:CurMove)], CurrentTime) != GrabSuccess)
|
None, cursor[((type) ? CurResize:CurMove)], CurrentTime) != GrabSuccess)
|
||||||
return;
|
return;
|
||||||
/* Warp pointer for resize */
|
/* Warp pointer for resize */
|
||||||
if(type && !c->tile)
|
if(type && !c->tile)
|
||||||
@@ -448,6 +441,7 @@ propertynotify(XEvent ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Handle */
|
/* Handle */
|
||||||
void
|
void
|
||||||
getevent(void)
|
getevent(void)
|
||||||
|
|||||||
@@ -35,11 +35,11 @@
|
|||||||
void
|
void
|
||||||
infobar_init(InfoBar *ib)
|
infobar_init(InfoBar *ib)
|
||||||
{
|
{
|
||||||
ib->geo.height = fonth + (float)4.5;
|
ib->geo.height = font->height + (float)4.5;
|
||||||
ib->geo.y = (conf.bartop) ? 0 : mh - ib->geo.height;
|
ib->geo.y = (conf.bartop) ? 0 : MAXH - ib->geo.height;
|
||||||
|
|
||||||
/* Create infobar barwindow */
|
/* Create infobar barwindow */
|
||||||
ib->bar = bar_create(0, ib->geo.y, mw, ib->geo.height, 0, conf.colors.bar, False);
|
ib->bar = bar_create(0, ib->geo.y, MAXW, ib->geo.height, 0, conf.colors.bar, False);
|
||||||
|
|
||||||
/* Create layout switch & layout type switch barwindow */
|
/* Create layout switch & layout type switch barwindow */
|
||||||
ib->layout_switch = bar_create(0, (conf.bartop) ? ib->geo.y : ib->geo.y + 1,
|
ib->layout_switch = bar_create(0, (conf.bartop) ? ib->geo.y : ib->geo.y + 1,
|
||||||
@@ -77,19 +77,23 @@ infobar_draw(void)
|
|||||||
sprintf(buf, "mwfact: %.2f - nmaster: %d",
|
sprintf(buf, "mwfact: %.2f - nmaster: %d",
|
||||||
tags[seltag].mwfact,
|
tags[seltag].mwfact,
|
||||||
tags[seltag].nmaster);
|
tags[seltag].nmaster);
|
||||||
draw_text(infobar.bar->dr, infobar.lastsep + PAD/1.5, fonth, conf.colors.text, conf.colors.bar, 0, buf);
|
draw_text(infobar.bar->dr, infobar.lastsep + PAD/1.5, font->height, conf.colors.text, conf.colors.bar, 0, buf);
|
||||||
draw_rectangle(infobar.bar->dr, textw(buf) + infobar.lastsep + PAD,
|
draw_rectangle(infobar.bar->dr, textw(buf) + infobar.lastsep + PAD,
|
||||||
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||||
|
|
||||||
/* Draw status text */
|
/* Draw status text */
|
||||||
draw_text(infobar.bar->dr, mw - textw(infobar.statustext), fonth, conf.colors.text, conf.colors.bar, 0, infobar.statustext);
|
draw_text(infobar.bar->dr,
|
||||||
|
MAXW - textw(infobar.statustext),
|
||||||
|
font->height,
|
||||||
|
conf.colors.text,
|
||||||
|
conf.colors.bar, 0, infobar.statustext);
|
||||||
|
|
||||||
/* Bar border */
|
/* Bar border */
|
||||||
if(conf.tagbordwidth)
|
if(conf.tagbordwidth)
|
||||||
{
|
{
|
||||||
draw_rectangle(infobar.bar->dr, 0, ((conf.bartop) ? infobar.geo.height - 1: 0),
|
draw_rectangle(infobar.bar->dr, 0, ((conf.bartop) ? infobar.geo.height - 1: 0),
|
||||||
mw, 1, conf.colors.tagbord);
|
MAXW, 1, conf.colors.tagbord);
|
||||||
draw_rectangle(infobar.bar->dr, mw - textw(infobar.statustext) - 5,
|
draw_rectangle(infobar.bar->dr, MAXW - textw(infobar.statustext) - 5,
|
||||||
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
0, conf.tagbordwidth, infobar.geo.height, conf.colors.tagbord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +123,7 @@ infobar_draw_layout(void)
|
|||||||
|
|
||||||
bar_move(infobar.layout_switch, px, py);
|
bar_move(infobar.layout_switch, px, py);
|
||||||
bar_resize(infobar.layout_switch, textw(symbol) + PAD, infobar.geo.height - 1);
|
bar_resize(infobar.layout_switch, textw(symbol) + PAD, infobar.geo.height - 1);
|
||||||
draw_text(infobar.layout_switch->dr, PAD/2, fonth,
|
draw_text(infobar.layout_switch->dr, PAD/2, font->height,
|
||||||
conf.colors.layout_fg,
|
conf.colors.layout_fg,
|
||||||
conf.colors.layout_bg,
|
conf.colors.layout_bg,
|
||||||
PAD, symbol);
|
PAD, symbol);
|
||||||
@@ -133,7 +137,7 @@ infobar_draw_layout(void)
|
|||||||
bar_refresh_color(infobar.layout_type_switch);
|
bar_refresh_color(infobar.layout_type_switch);
|
||||||
bar_move(infobar.layout_type_switch, px + infobar.layout_switch->geo.width + PAD/2, py);
|
bar_move(infobar.layout_type_switch, px + infobar.layout_switch->geo.width + PAD/2, py);
|
||||||
bar_resize(infobar.layout_type_switch, textw(tags[seltag].layout.symbol) + PAD, infobar.geo.height - 1);
|
bar_resize(infobar.layout_type_switch, textw(tags[seltag].layout.symbol) + PAD, infobar.geo.height - 1);
|
||||||
draw_text(infobar.layout_type_switch->dr, PAD/2, fonth,
|
draw_text(infobar.layout_type_switch->dr, PAD/2, font->height,
|
||||||
conf.colors.layout_fg,
|
conf.colors.layout_fg,
|
||||||
conf.colors.layout_bg,
|
conf.colors.layout_bg,
|
||||||
PAD, tags[seltag].layout.symbol);
|
PAD, tags[seltag].layout.symbol);
|
||||||
@@ -166,7 +170,7 @@ infobar_draw_taglist(Drawable dr)
|
|||||||
sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : "");
|
sprintf(buf[i], "%s<%s>", tags[i+1].name, (client_pertag(i+1)) ? p : "");
|
||||||
|
|
||||||
/* Draw the string */
|
/* Draw the string */
|
||||||
draw_text(dr, taglen[i], fonth,
|
draw_text(dr, taglen[i], font->height,
|
||||||
((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text),
|
((i+1 == seltag) ? conf.colors.tagselfg : conf.colors.text),
|
||||||
((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]);
|
((i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar), PAD, buf[i]);
|
||||||
|
|
||||||
@@ -189,7 +193,7 @@ uicb_infobar_togglepos(uicb_t cmd)
|
|||||||
sgeo.y = conf.titlebar.pos ? infobar.geo.height : infobar.geo.height + conf.titlebar.height;
|
sgeo.y = conf.titlebar.pos ? infobar.geo.height : infobar.geo.height + conf.titlebar.height;
|
||||||
else
|
else
|
||||||
sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height;
|
sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height;
|
||||||
infobar.geo.y = (conf.bartop) ? 0 : mh - infobar.geo.height;
|
infobar.geo.y = (conf.bartop) ? 0 : MAXH - infobar.geo.height;
|
||||||
bar_move(infobar.bar, 0, infobar.geo.y);
|
bar_move(infobar.bar, 0, infobar.geo.y);
|
||||||
infobar_draw();
|
infobar_draw();
|
||||||
arrange();
|
arrange();
|
||||||
|
|||||||
149
src/init.c
Normal file
149
src/init.c
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* wmfs.c
|
||||||
|
* Copyright © 2008 Martin Duquesnoy <xorg62@gmail.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of the nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wmfs.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
init(void)
|
||||||
|
{
|
||||||
|
/* First init */
|
||||||
|
gc = DefaultGC (dpy, screen);
|
||||||
|
screen = DefaultScreen (dpy);
|
||||||
|
root = RootWindow (dpy, screen);
|
||||||
|
|
||||||
|
init_font();
|
||||||
|
init_cursor();
|
||||||
|
init_key();
|
||||||
|
init_atom();
|
||||||
|
init_root();
|
||||||
|
infobar_init(&infobar);
|
||||||
|
init_geometry();
|
||||||
|
grabkeys();
|
||||||
|
|
||||||
|
/* Warning about font */
|
||||||
|
if(conf.titlebar.height < font->height)
|
||||||
|
fprintf(stderr, "WMFS Warning: Font too big, can't draw any text in the titlebar.\n");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_font(void)
|
||||||
|
{
|
||||||
|
font = XftFontOpenName(dpy, screen, conf.font);
|
||||||
|
if(!font)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "WMFS Error: Cannot initialize font\n");
|
||||||
|
font = XftFontOpenName(dpy, screen, "sans-10");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_cursor(void)
|
||||||
|
{
|
||||||
|
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
||||||
|
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
||||||
|
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_key(void)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
XModifierKeymap *modmap = XGetModifierMapping(dpy);
|
||||||
|
|
||||||
|
for(i = 0; i < 8; i++)
|
||||||
|
for(j = 0; j < modmap->max_keypermod; ++j)
|
||||||
|
{
|
||||||
|
if(modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||||
|
== XKeysymToKeycode(dpy, XK_Num_Lock))
|
||||||
|
numlockmask = (1 << i);
|
||||||
|
if(modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||||
|
== XKeysymToKeycode(dpy, XK_Scroll_Lock))
|
||||||
|
scrolllockmask = (1 << i);
|
||||||
|
}
|
||||||
|
XFreeModifiermap(modmap);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_atom(void)
|
||||||
|
{
|
||||||
|
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
|
||||||
|
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||||
|
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||||
|
wm_atom[WMName] = XInternAtom(dpy, "WM_NAME", False);
|
||||||
|
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||||
|
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||||
|
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
|
||||||
|
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_root(void)
|
||||||
|
{
|
||||||
|
XSetWindowAttributes at;
|
||||||
|
|
||||||
|
at.event_mask = KeyMask | ButtonPressMask | ButtonReleaseMask |
|
||||||
|
SubstructureRedirectMask | SubstructureNotifyMask |
|
||||||
|
EnterWindowMask | LeaveWindowMask | StructureNotifyMask ;
|
||||||
|
at.cursor = cursor[CurNormal];
|
||||||
|
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at);
|
||||||
|
if(conf.root.background_command)
|
||||||
|
uicb_spawn(conf.root.background_command);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_geometry(void)
|
||||||
|
{
|
||||||
|
sgeo.x = 0;
|
||||||
|
|
||||||
|
if(conf.bartop)
|
||||||
|
sgeo.y = (conf.titlebar.pos)
|
||||||
|
? infobar.geo.height
|
||||||
|
: infobar.geo.height + conf.titlebar.height;
|
||||||
|
else
|
||||||
|
sgeo.y = (conf.titlebar.pos)
|
||||||
|
? 0
|
||||||
|
: conf.titlebar.height;
|
||||||
|
|
||||||
|
sgeo.width = MAXW;
|
||||||
|
sgeo.height = MAXH - (infobar.geo.height + conf.titlebar.height);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
@@ -88,7 +88,7 @@ struct Client
|
|||||||
/* Border */
|
/* Border */
|
||||||
int border;
|
int border;
|
||||||
/* Client Layout Information */
|
/* Client Layout Information */
|
||||||
Bool max, tile, free;
|
Bool max, tile, free, hide;
|
||||||
Bool hint, lmax, havetbar;
|
Bool hint, lmax, havetbar;
|
||||||
/* Struct in chains */
|
/* Struct in chains */
|
||||||
Client *next;
|
Client *next;
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ titlebar_update(Client *c)
|
|||||||
bar_refresh_color(c->tbar);
|
bar_refresh_color(c->tbar);
|
||||||
|
|
||||||
/* Draw the client title in the titlebar *logeek* */
|
/* Draw the client title in the titlebar *logeek* */
|
||||||
if(conf.titlebar.height + 1 > fonth)
|
if(conf.titlebar.height + 1 > font->height)
|
||||||
{
|
{
|
||||||
/* Set the text alignement */
|
/* Set the text alignement */
|
||||||
switch(conf.titlebar.text_align)
|
switch(conf.titlebar.text_align)
|
||||||
@@ -148,7 +148,7 @@ titlebar_update(Client *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set y text position (always at the middle) and fg color */
|
/* Set y text position (always at the middle) and fg color */
|
||||||
pos_y = (fonth - (xftfont->descent ) - 1) + ((conf.titlebar.height - fonth) / 2);
|
pos_y = (font->height - (font->descent ) - 1) + ((conf.titlebar.height - font->height) / 2);
|
||||||
|
|
||||||
/* Draw title */
|
/* Draw title */
|
||||||
draw_text(c->tbar->dr, pos_x, pos_y, fg, bg, 0, c->title);
|
draw_text(c->tbar->dr, pos_x, pos_y, fg, bg, 0, c->title);
|
||||||
|
|||||||
21
src/util.c
21
src/util.c
@@ -62,6 +62,27 @@ getcolor(char *color)
|
|||||||
return xcolor.pixel;
|
return xcolor.pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
getwinstate(Window win)
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
long ret = -1;
|
||||||
|
ulong n, e;
|
||||||
|
uchar *p = NULL;
|
||||||
|
Atom at;
|
||||||
|
|
||||||
|
if(XGetWindowProperty(dpy, win, wm_atom[WMState], 0L, 2L, False, wm_atom[WMState],
|
||||||
|
&at, &f, &n, &e, (uchar **)&p) != Success)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if(n != 0)
|
||||||
|
ret = *p;
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
round(double x)
|
round(double x)
|
||||||
{
|
{
|
||||||
|
|||||||
85
src/wmfs.c
85
src/wmfs.c
@@ -88,7 +88,7 @@ void
|
|||||||
quit(void)
|
quit(void)
|
||||||
{
|
{
|
||||||
/* Exiting WMFS :'( */
|
/* Exiting WMFS :'( */
|
||||||
XftFontClose(dpy, xftfont);
|
XftFontClose(dpy, font);
|
||||||
XFreeCursor(dpy, cursor[CurNormal]);
|
XFreeCursor(dpy, cursor[CurNormal]);
|
||||||
XFreeCursor(dpy, cursor[CurMove]);
|
XFreeCursor(dpy, cursor[CurMove]);
|
||||||
XFreeCursor(dpy, cursor[CurResize]);
|
XFreeCursor(dpy, cursor[CurResize]);
|
||||||
@@ -104,89 +104,6 @@ quit(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
init(void)
|
|
||||||
{
|
|
||||||
XSetWindowAttributes at;
|
|
||||||
XModifierKeymap *modmap;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
/* FIRST INIT */
|
|
||||||
gc = DefaultGC (dpy, screen);
|
|
||||||
screen = DefaultScreen (dpy);
|
|
||||||
root = RootWindow (dpy, screen);
|
|
||||||
mw = DisplayWidth (dpy, screen);
|
|
||||||
mh = DisplayHeight (dpy, screen);
|
|
||||||
|
|
||||||
|
|
||||||
/* INIT TAG / LAYOUT ATTRIBUTE */
|
|
||||||
seltag = 1;
|
|
||||||
for(i = 0; i < conf.ntag + 1; ++i)
|
|
||||||
tags[i] = conf.tag[i - 1];
|
|
||||||
|
|
||||||
/* INIT FONT */
|
|
||||||
xftfont = XftFontOpenName(dpy, screen, conf.font);
|
|
||||||
if(!xftfont)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "WMFS Error: Cannot initialize font\n");
|
|
||||||
xftfont = XftFontOpenName(dpy, screen, "sans-10");
|
|
||||||
}
|
|
||||||
fonth = (xftfont->ascent + xftfont->descent);
|
|
||||||
|
|
||||||
/* INIT CURSOR */
|
|
||||||
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
|
||||||
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
|
||||||
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
|
|
||||||
|
|
||||||
/* INIT MODIFIER */
|
|
||||||
modmap = XGetModifierMapping(dpy);
|
|
||||||
for(i = 0; i < 8; i++)
|
|
||||||
for(j = 0; j < modmap->max_keypermod; ++j)
|
|
||||||
if(modmap->modifiermap[i * modmap->max_keypermod + j]
|
|
||||||
== XKeysymToKeycode(dpy, XK_Num_Lock))
|
|
||||||
numlockmask = (1 << i);
|
|
||||||
XFreeModifiermap(modmap);
|
|
||||||
|
|
||||||
/* INIT ATOM */
|
|
||||||
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
|
|
||||||
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
|
||||||
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
|
||||||
net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
|
||||||
net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
|
||||||
XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
|
|
||||||
PropModeReplace, (unsigned char *) net_atom, NetLast);
|
|
||||||
|
|
||||||
/* INIT ROOT */
|
|
||||||
at.event_mask = KeyMask | ButtonPressMask | ButtonReleaseMask |
|
|
||||||
SubstructureRedirectMask | SubstructureNotifyMask |
|
|
||||||
EnterWindowMask | LeaveWindowMask | StructureNotifyMask ;
|
|
||||||
at.cursor = cursor[CurNormal];
|
|
||||||
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &at);
|
|
||||||
if(conf.root.background_command)
|
|
||||||
uicb_spawn(conf.root.background_command);
|
|
||||||
|
|
||||||
/* INIT INFOBAR */
|
|
||||||
infobar_init(&infobar);
|
|
||||||
|
|
||||||
/* INIT WORKABLE SPACE GEOMETRY */
|
|
||||||
sgeo.x = 0;
|
|
||||||
if(conf.bartop)
|
|
||||||
sgeo.y = conf.titlebar.pos ? infobar.geo.height : infobar.geo.height + conf.titlebar.height;
|
|
||||||
else
|
|
||||||
sgeo.y = conf.titlebar.pos ? 0 : conf.titlebar.height;
|
|
||||||
sgeo.width = DisplayWidth(dpy, screen);
|
|
||||||
sgeo.height = DisplayHeight(dpy, screen) - (infobar.geo.height + conf.titlebar.height);
|
|
||||||
|
|
||||||
/* INIT STUFF */
|
|
||||||
grabkeys();
|
|
||||||
|
|
||||||
/* MISC WARNING */
|
|
||||||
if(conf.titlebar.height < fonth)
|
|
||||||
fprintf(stderr, "WMFS Warning: Font too big, can't draw any text in the titlebar.\n");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mainloop(void)
|
mainloop(void)
|
||||||
{
|
{
|
||||||
|
|||||||
17
src/wmfs.h
17
src/wmfs.h
@@ -57,6 +57,8 @@
|
|||||||
#define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
|
#define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
|
||||||
#define MouseMask (ButtonMask | PointerMotionMask)
|
#define MouseMask (ButtonMask | PointerMotionMask)
|
||||||
#define KeyMask (KeyPressMask | KeyReleaseMask)
|
#define KeyMask (KeyPressMask | KeyReleaseMask)
|
||||||
|
#define MAXH DisplayHeight(dpy, screen)
|
||||||
|
#define MAXW DisplayWidth(dpy, screen)
|
||||||
#define ITOA(p ,n) sprintf(p, "%d", n)
|
#define ITOA(p ,n) sprintf(p, "%d", n)
|
||||||
#define debug(p) fprintf(stderr, "debug: %d\n", p)
|
#define debug(p) fprintf(stderr, "debug: %d\n", p)
|
||||||
#define PAD 8
|
#define PAD 8
|
||||||
@@ -168,13 +170,21 @@ void uicb_layout_next(uicb_t);
|
|||||||
void uicb_set_mwfact(uicb_t);
|
void uicb_set_mwfact(uicb_t);
|
||||||
void uicb_set_nmaster(uicb_t);
|
void uicb_set_nmaster(uicb_t);
|
||||||
|
|
||||||
|
/* init.c */
|
||||||
|
void init(void);
|
||||||
|
void init_atom(void);
|
||||||
|
void init_font(void);
|
||||||
|
void init_cursor(void);
|
||||||
|
void init_root(void);
|
||||||
|
void init_key(void);
|
||||||
|
void init_geometry(void);
|
||||||
|
|
||||||
/* wmfs.c */
|
/* wmfs.c */
|
||||||
void checkotherwm(void);
|
void checkotherwm(void);
|
||||||
int errorhandler(Display *d, XErrorEvent *event);
|
int errorhandler(Display *d, XErrorEvent *event);
|
||||||
int errorhandlerdummy(Display *d, XErrorEvent *event);
|
int errorhandlerdummy(Display *d, XErrorEvent *event);
|
||||||
int errorhandlerstart(Display *d, XErrorEvent *event);
|
int errorhandlerstart(Display *d, XErrorEvent *event);
|
||||||
void quit(void);
|
void quit(void);
|
||||||
void init(void);
|
|
||||||
void mainloop(void);
|
void mainloop(void);
|
||||||
void scan(void);
|
void scan(void);
|
||||||
void uicb_quit(uicb_t);
|
void uicb_quit(uicb_t);
|
||||||
@@ -188,7 +198,6 @@ GC gc;
|
|||||||
Window root;
|
Window root;
|
||||||
XRectangle sgeo;
|
XRectangle sgeo;
|
||||||
int screen;
|
int screen;
|
||||||
int mw, mh;
|
|
||||||
Conf conf;
|
Conf conf;
|
||||||
Key *keys;
|
Key *keys;
|
||||||
Bool exiting;
|
Bool exiting;
|
||||||
@@ -200,8 +209,7 @@ Atom net_atom[NetLast];
|
|||||||
Cursor cursor[CurLast];
|
Cursor cursor[CurLast];
|
||||||
|
|
||||||
/* Fonts */
|
/* Fonts */
|
||||||
int fonth;
|
XftFont *font;
|
||||||
XftFont *xftfont;
|
|
||||||
|
|
||||||
/* InfoBar */
|
/* InfoBar */
|
||||||
InfoBar infobar;
|
InfoBar infobar;
|
||||||
@@ -216,6 +224,7 @@ Client *selbytag[MAXTAG];
|
|||||||
|
|
||||||
/* Other */
|
/* Other */
|
||||||
uint numlockmask;
|
uint numlockmask;
|
||||||
|
uint scrolllockmask;
|
||||||
Variable confvar[256];
|
Variable confvar[256];
|
||||||
|
|
||||||
#endif /* WMFS_H */
|
#endif /* WMFS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user