KeySym key = XKeycodeToKeysym(dsply, e->keycode, 0);
switch (key)
{
- case KEY_CYCLEPREV:
- cycle_previous();
- break;
- case KEY_CYCLENEXT:
- cycle_next();
- break;
case KEY_FULLSCREEN:
toggle_fullscreen(focused_client);
break;
dump_clients();
#endif
}
- else if (e->window == taskbar)
- {
- switch (e->button)
- {
- case Button1: // left mouse button
- lclick_taskbar(e->x);
- break;
- case Button4: // mouse wheel up
- cycle_previous();
- break;
- case Button5: // mouse wheel down
- cycle_next();
- break;
- }
- }
else
{
// pass event on
}
XFetchName(dsply, c->window, &c->name);
redraw(c);
- redraw_taskbar();
break;
case XA_WM_NORMAL_HINTS:
XGetWMNormalHints(dsply, c->window, c->size, &dummy);
static void handle_enter_event(XCrossingEvent *e)
{
Client *c = NULL;
- if (e->window == taskbar)
- {
- in_taskbar = 1;
- if (showing_taskbar == 0)
- {
- showing_taskbar = 1;
- redraw_taskbar();
- }
- }
- else
- {
- in_taskbar = 0;
- if (fullscreen_client != NULL)
- {
- if (showing_taskbar == 1)
- {
- showing_taskbar = 0;
- redraw_taskbar();
- }
- }
- else // no fullscreen client
- {
- if (showing_taskbar == 0)
- {
- showing_taskbar = 1;
- redraw_taskbar();
- }
- }
c = find_client(e->window, FRAME);
if (c != NULL)
{
XGrabButton(dsply, AnyButton, AnyModifier, c->frame, False, ButtonMask, GrabModeSync, GrabModeSync, None, None);
}
- }
}
/* Here's part 2 of our colormap policy: when a client installs a new
static void handle_expose_event(XExposeEvent *e)
{
- if (e->window == taskbar)
- {
- if (e->count == 0)
- {
- redraw_taskbar();
- }
- }
- else
- {
Client *c = find_client(e->window, FRAME);
if (c != NULL && e->count == 0)
{
redraw(c);
}
- }
}
/* interruptibleXNextEvent() was originally taken from Blender's source code
fullscreen_client = c;
showing_taskbar = in_taskbar;
}
- redraw_taskbar();
}
}
}
}
break;
- case MotionNotify:
- {
- unsigned int in_taskbar = 1, leftedge_changed = 0, rightedge_changed = 0, topedge_changed = 0, bottomedge_changed = 0;
- int newwidth, newheight;
- // warping the pointer is wrong - wait until it leaves the taskbar
- if (ev.xmotion.y < BARHEIGHT())
- {
- in_taskbar = 1;
- }
- else
- {
- if (in_taskbar == 1) // first time outside taskbar
- {
- in_taskbar = 0;
- bounddims.x = 0;
- bounddims.width = dw;
- bounddims.y = BARHEIGHT();
- bounddims.height = dh - BARHEIGHT();
- XMoveResizeWindow(dsply, constraint_win, bounddims.x, bounddims.y, bounddims.width, bounddims.height);
- in_taskbar = 0;
- }
- // inside the window, dragging outwards
- if (dragging_outwards)
- {
- if (ev.xmotion.x < newdims.x + BORDERWIDTH(c))
- {
- newdims.width += newdims.x + BORDERWIDTH(c) - ev.xmotion.x;
- newdims.x = ev.xmotion.x - BORDERWIDTH(c);
- leftedge_changed = 1;
- }
- else if (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c))
- {
- newdims.width = (ev.xmotion.x - newdims.x - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen
- rightedge_changed = 1;
- }
- if (ev.xmotion.y < newdims.y + BORDERWIDTH(c))
- {
- newdims.height += newdims.y + BORDERWIDTH(c) - ev.xmotion.y;
- newdims.y = ev.xmotion.y - BORDERWIDTH(c);
- topedge_changed = 1;
- }
- else if (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c))
- {
- newdims.height = (ev.xmotion.y - newdims.y - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen
- bottomedge_changed = 1;
- }
- }
- // outside the window, dragging inwards
- else
- {
- unsigned int above_win, below_win, leftof_win, rightof_win;
- unsigned int in_win;
-
- above_win = (ev.xmotion.y < newdims.y + BORDERWIDTH(c));
- below_win = (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c));
- leftof_win = (ev.xmotion.x < newdims.x + BORDERWIDTH(c));
- rightof_win = (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c));
-
- in_win = ((!above_win) && (!below_win) && (!leftof_win) && (!rightof_win));
-
- if (in_win)
- {
- unsigned int from_left, from_right, from_top, from_bottom;
- from_left = ev.xmotion.x - newdims.x - BORDERWIDTH(c);
- from_right = newdims.x + newdims.width + BORDERWIDTH(c) - ev.xmotion.x;
- from_top = ev.xmotion.y - newdims.y - BORDERWIDTH(c);
- from_bottom = newdims.y + newdims.height + BORDERWIDTH(c) - ev.xmotion.y;
- if (from_left < from_right && from_left < from_top && from_left < from_bottom)
- {
- newdims.width -= ev.xmotion.x - newdims.x - BORDERWIDTH(c);
- newdims.x = ev.xmotion.x - BORDERWIDTH(c);
- leftedge_changed = 1;
- }
- else if (from_right < from_top && from_right < from_bottom)
- {
- newdims.width = ev.xmotion.x - newdims.x - BORDERWIDTH(c);
- rightedge_changed = 1;
- }
- else if (from_top < from_bottom)
- {
- newdims.height -= ev.xmotion.y - newdims.y - BORDERWIDTH(c);
- newdims.y = ev.xmotion.y - BORDERWIDTH(c);
- topedge_changed = 1;
- }
- else
- {
- newdims.height = ev.xmotion.y - newdims.y - BORDERWIDTH(c);
- bottomedge_changed = 1;
- }
- }
- }
- // coords have changed
- if (leftedge_changed || rightedge_changed || topedge_changed || bottomedge_changed)
- {
- copy_dims(&newdims, &recalceddims);
- recalceddims.height -= BARHEIGHT();
-
- if (get_incsize(c, (unsigned int *)&newwidth, (unsigned int *)&newheight, &recalceddims, PIXELS))
- {
- if (leftedge_changed)
- {
- recalceddims.x = (recalceddims.x + recalceddims.width) - newwidth;
- recalceddims.width = newwidth;
- }
- else if (rightedge_changed)
- {
- recalceddims.width = newwidth;
- }
-
- if (topedge_changed)
- {
- recalceddims.y = (recalceddims.y + recalceddims.height) - newheight;
- recalceddims.height = newheight;
- }
- else if (bottomedge_changed)
- {
- recalceddims.height = newheight;
- }
- }
-
- recalceddims.height += BARHEIGHT();
- limit_size(c, &recalceddims);
-
- XMoveResizeWindow(dsply, resize_win, recalceddims.x, recalceddims.y, recalceddims.width, recalceddims.height);
- XResizeWindow(dsply, resizebar_win, recalceddims.width, BARHEIGHT() - DEF_BORDERWIDTH);
- }
- }
- }
- break;
}
}
while (ev.type != ButtonRelease);
+++ /dev/null
-/* WindowLab - an X11 window manager
- * Copyright (c) 2001-2010 Nick Gravgaard
- * me at nickgravgaard.com
- * http://nickgravgaard.com/windowlab/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-#include "windowlab.h"
-
-Window taskbar;
-XftDraw *tbxftdraw;
-
-void make_taskbar(void)
-{
- XSetWindowAttributes pattr;
-
- pattr.override_redirect = True;
- pattr.background_pixel = empty_col.pixel;
- pattr.border_pixel = border_col.pixel;
- pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask;
- taskbar = XCreateWindow(dsply, root, 0 - DEF_BORDERWIDTH, 0 - DEF_BORDERWIDTH, DisplayWidth(dsply, screen), BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr);
-
- XMapWindow(dsply, taskbar);
-
- tbxftdraw = XftDrawCreate(dsply, (Drawable) taskbar, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply)));
-}
-
-void remember_hidden(void)
-{
- Client *c;
- for (c = head_client; c != NULL; c = c->next)
- {
- c->was_hidden = c->hidden;
- }
-}
-
-void forget_hidden(void)
-{
- Client *c;
- for (c = head_client; c != NULL; c = c->next)
- {
- if (c == focused_client)
- {
- c->was_hidden = c->hidden;
- }
- else
- {
- c->was_hidden = 0;
- }
- }
-}
-
-void lclick_taskbutton(Client *old_c, Client *c)
-{
- if (old_c != NULL)
- {
- if (old_c->was_hidden)
- {
- hide(old_c);
- }
- }
-
- if (c->hidden)
- {
- unhide(c);
- }
- else
- {
- if (c->was_hidden)
- {
- hide(c);
- }
- else
- {
- raise_lower(c);
- }
- }
- check_focus(c);
-}
-
-void lclick_taskbar(int x)
-{
- XEvent ev;
- int mousex, mousey;
- Rect bounddims;
- Window constraint_win;
- XSetWindowAttributes pattr;
-
- float button_width;
- unsigned int button_clicked, old_button_clicked, i;
- Client *c, *exposed_c, *old_c;
- if (head_client != NULL)
- {
- remember_hidden();
-
- get_mouse_position(&mousex, &mousey);
-
- bounddims.x = 0;
- bounddims.y = 0;
- bounddims.width = DisplayWidth(dsply, screen);
- bounddims.height = BARHEIGHT();
-
- constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr);
- XMapWindow(dsply, constraint_win);
-
- if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess))
- {
- XDestroyWindow(dsply, constraint_win);
- return;
- }
-
- button_width = get_button_width();
-
- button_clicked = (unsigned int)(x / button_width);
- for (i = 0, c = head_client; i < button_clicked; i++)
- {
- c = c->next;
- }
-
- lclick_taskbutton(NULL, c);
-
- do
- {
- XMaskEvent(dsply, ExposureMask|MouseMask|KeyMask, &ev);
- switch (ev.type)
- {
- case Expose:
- exposed_c = find_client(ev.xexpose.window, FRAME);
- if (exposed_c)
- {
- redraw(exposed_c);
- }
- break;
- case MotionNotify:
- old_button_clicked = button_clicked;
- button_clicked = (unsigned int)(ev.xmotion.x / button_width);
- if (button_clicked != old_button_clicked)
- {
- old_c = c;
- for (i = 0, c = head_client; i < button_clicked; i++)
- {
- c = c->next;
- }
- lclick_taskbutton(old_c, c);
- }
- break;
- case KeyPress:
- XPutBackEvent(dsply, &ev);
- break;
- }
- }
- while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress);
-
- XUnmapWindow(dsply, constraint_win);
- XDestroyWindow(dsply, constraint_win);
- ungrab();
-
- forget_hidden();
- }
-}
-
-void redraw_taskbar(void)
-{
- unsigned int i;
- int button_startx, button_iwidth;
- float button_width;
- Client *c;
-
- button_width = get_button_width();
- XClearWindow(dsply, taskbar);
-
- if (showing_taskbar == 0)
- {
- return;
- }
-
- for (c = head_client, i = 0; c != NULL; c = c->next, i++)
- {
- button_startx = (int)(i * button_width);
- button_iwidth = (unsigned int)(((i + 1) * button_width) - button_startx);
- if (button_startx != 0)
- {
- XDrawLine(dsply, taskbar, border_gc, button_startx - 1, 0, button_startx - 1, BARHEIGHT() - DEF_BORDERWIDTH);
- }
- if (c == focused_client)
- {
- XFillRectangle(dsply, taskbar, active_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH);
- }
- else
- {
- XFillRectangle(dsply, taskbar, inactive_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH);
- }
- if (!c->trans && c->name != NULL)
- {
- XftDrawString8(tbxftdraw, &xft_detail, xftfont, button_startx + SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name));
- }
- }
-}
-
-float get_button_width(void)
-{
- unsigned int nwins = 0;
- Client *c = head_client;
- while (c != NULL)
- {
- nwins++;
- c = c->next;
- }
- return ((float)(DisplayWidth(dsply, screen) + DEF_BORDERWIDTH)) / nwins;
-}
-
-void cycle_previous(void)
-{
- Client *c = focused_client;
- Client *original_c = c;
- if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist
- {
- if (c == NULL)
- {
- c = head_client;
- }
- if (c == head_client)
- {
- original_c = NULL;
- }
- do
- {
- if (c->next == NULL)
- {
- c = head_client;
- }
- else
- {
- c = c->next;
- }
- }
- while (c->next != original_c);
- lclick_taskbutton(NULL, c);
- }
-}
-
-void cycle_next(void)
-{
- Client *c = focused_client;
- if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist
- {
- if (c == NULL || c->next == NULL)
- {
- c = head_client;
- }
- else c = c->next;
- lclick_taskbutton(NULL, c);
- }
-}