added new events (focus page and focus client provide the associated name)

This commit is contained in:
Anselm R. Garbe 2006-02-10 17:51:20 +01:00
parent b7941ad804
commit 918ece162d
6 changed files with 55 additions and 37 deletions

View File

@ -90,6 +90,14 @@ set_client_state(Client * c, int state)
(unsigned char *) data, 2);
}
static void
client_name_event(Client *c)
{
char buf[256];
snprintf(buf, sizeof(buf), "C %s\n", c->name);
do_pend_fcall(buf);
}
void
focus_client(Client *c)
{
@ -125,7 +133,7 @@ focus_client(Client *c)
XDefineCursor(dpy, c->win, normal_cursor);
draw_client(c);
XSync(dpy, False);
/* TODO: client update */
client_name_event(c);
}
void
@ -218,7 +226,7 @@ handle_client_property(Client *c, XPropertyEvent *e)
}
if(c->page)
draw_client(c);
/* TODO: client update */
client_name_event(c);
break;
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &c->trans);
@ -381,8 +389,6 @@ attach_client(Client *c)
map_client(c);
XMapWindow(dpy, c->frame.win);
focus_client(c);
/* TODO: page update event */
}
void

View File

@ -82,6 +82,8 @@ focus_page(Page *p)
{
size_t i;
Page *old = page ? page[sel] : nil;
char buf[16];
Client *c;
if(!page)
return;
@ -92,7 +94,7 @@ focus_page(Page *p)
sel = i;
for(i = 0; i < nclient; i++) {
Client *c = client[i];
c = client[i];
if(old && (c->page == old))
XMoveWindow(dpy, c->frame.win, 2 * rect.width, 2 * rect.height);
else if(c->page == p) {
@ -100,7 +102,10 @@ focus_page(Page *p)
draw_client(c);
}
}
do_pend_fcall("SelPage\n");
if((c = sel_client_of_page(p)))
focus_client(c);
snprintf(buf, sizeof(buf), "P %d\n", sel + 1);
do_pend_fcall(buf);
XChangeProperty(dpy, root, net_atoms[NET_CURRENT_DESKTOP], XA_CARDINAL,
32, PropModeReplace, (unsigned char *) &sel, 1);
XSync(dpy, False);
@ -245,3 +250,28 @@ pid_to_index(unsigned short id)
return i;
return -1;
}
void
select_page(char *arg)
{
size_t new = sel;
const char *err;
if(!npage || !arg)
return;
if(!strncmp(arg, "prev", 5)) {
if(new > 0)
for(new = 0; page[new]; new++);
new--;
} else if(!strncmp(arg, "next", 5)) {
if(page[new + 1])
new++;
else
new = 0;
} else {
int idx = cext_strtonum(arg, 0, npage, &err);
if(idx < npage)
new = idx;
}
focus_page(page[new]);
}

View File

@ -330,31 +330,6 @@ attach_detached_client()
}
}
void
select_page(char *arg)
{
size_t new = sel;
const char *err;
if(!npage || !arg)
return;
if(!strncmp(arg, "prev", 5)) {
if(new > 0)
for(new = 0; page[new]; new++);
new--;
} else if(!strncmp(arg, "next", 5)) {
if(page[new + 1])
new++;
else
new = 0;
} else {
int idx = cext_strtonum(arg, 0, npage, &err);
if(idx < npage)
new = idx;
}
focus_page(page[new]);
}
Client *
win_to_client(Window w)
{

View File

@ -259,6 +259,7 @@ void destroy_page(Page *p);
void focus_page(Page *p);
XRectangle *rectangles(unsigned int *num);
int pid_to_index(unsigned short id);
void select_page(char *arg);
/* spawn.c */
void spawn(char *cmd);
@ -281,5 +282,4 @@ int win_state(Window w);
void pager();
void detached_clients();
void attach_detached_client();
void select_page(char *arg);

View File

@ -23,7 +23,7 @@ fn statustext {
}
text=`{statustext}
while(xwrite /bar/1/data $"text) {
while(xwrite /bar/3/data $"text) {
sleep 2
text=`{statustext}
}

View File

@ -25,7 +25,7 @@ MODKEY=Alt
# WMIIWM CONFIGURATION
xwrite /def/bar $CLIENT_BAR
xwrite /def/border $CLIENT_BORDER
xwrite /def/handleinc 1
xwrite /def/inc 1
xwrite /def/snap 20
#xwrite /def/font $FONT
#xwrite /def/selcolor $SEL_COLOR
@ -67,8 +67,10 @@ for(i in 1 2 3 4 5 6 7 8 9)
# WMIIBAR CONFIGURATION
xwrite /bar/new/data status
xwrite /bar/new/data event
xwrite /bar/new/data 1
xwrite /bar/new/data ''
xwrite /bar/new/data fnord
xwrite /bar/expand 2
# MISC
@ -78,7 +80,12 @@ status &
# EVENT LOOP
wmiir read /event | \
while(event=`{read}) {
xwrite /bar/2/data $"event
if(~ $event(1) P)
xwrite /bar/1/data $event(2)
if(~ $event(1) C) {
text=`{echo $"event | sed 's/^C //g'}
xwrite /bar/2/data $"text
}
if(~ $event(1) K) { # key press
switch($event(2)) {
case $MODKEY-Control-c