2009-01-13 15:55:13 +00:00
|
|
|
/*
|
2012-01-22 03:38:04 +08:00
|
|
|
* Copyright (c) 2009-2012 Marco Peereboom <marco@peereboom.us>
|
|
|
|
* Copyright (c) 2009-2011 Ryan McBride <mcbride@countersiege.com>
|
2009-03-10 01:32:06 +00:00
|
|
|
* Copyright (c) 2009 Darrin Chandler <dwchandler@stilyagin.com>
|
2009-06-04 17:22:43 +00:00
|
|
|
* Copyright (c) 2009 Pierre-Yves Ritschard <pyr@spootnik.org>
|
2011-07-18 16:09:43 +00:00
|
|
|
* Copyright (c) 2010 Tuukka Kataja <stuge@xor.fi>
|
2011-06-06 19:54:48 +00:00
|
|
|
* Copyright (c) 2011 Jason L. Wright <jason@thought.net>
|
2012-01-22 03:38:04 +08:00
|
|
|
* Copyright (c) 2011-2012 Reginald Kennedy <rk@rejii.com>
|
2012-02-15 23:45:50 -05:00
|
|
|
* Copyright (c) 2011-2012 Lawrence Teo <lteo@lteo.net>
|
|
|
|
* Copyright (c) 2011-2012 Tiago Cunha <tcunha@gmx.com>
|
2009-01-13 15:55:13 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Much code and ideas taken from dwm under the following license:
|
|
|
|
* MIT/X Consortium License
|
2009-08-30 18:16:41 +00:00
|
|
|
*
|
2009-01-13 15:55:13 +00:00
|
|
|
* 2006-2008 Anselm R Garbe <garbeam at gmail dot com>
|
|
|
|
* 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
|
|
|
* 2006-2007 Jukka Salmi <jukka at salmi dot ch>
|
|
|
|
* 2007 Premysl Hruby <dfenze at gmail dot com>
|
|
|
|
* 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
|
|
|
|
* 2007 Christof Musik <christof at sendfax dot de>
|
|
|
|
* 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
|
|
|
|
* 2007-2008 Peter Hartlich <sgkkr at hartlich dot com>
|
|
|
|
* 2008 Martin Hurton <martin dot hurton at gmail dot com>
|
2009-08-30 18:16:41 +00:00
|
|
|
*
|
2009-01-13 15:55:13 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2009-08-30 18:16:41 +00:00
|
|
|
*
|
2009-01-13 15:55:13 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2009-08-30 18:16:41 +00:00
|
|
|
*
|
2009-01-13 15:55:13 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <err.h>
|
2009-01-19 19:27:36 +00:00
|
|
|
#include <errno.h>
|
2009-01-22 17:50:16 +00:00
|
|
|
#include <fcntl.h>
|
2009-01-13 15:55:13 +00:00
|
|
|
#include <locale.h>
|
|
|
|
#include <unistd.h>
|
2009-01-14 04:44:58 +00:00
|
|
|
#include <time.h>
|
2009-01-14 06:08:16 +00:00
|
|
|
#include <signal.h>
|
2009-01-14 05:14:13 +00:00
|
|
|
#include <string.h>
|
2009-01-14 17:10:52 +00:00
|
|
|
#include <util.h>
|
|
|
|
#include <pwd.h>
|
2010-07-15 13:58:25 +00:00
|
|
|
#include <paths.h>
|
2009-01-20 06:16:05 +00:00
|
|
|
#include <ctype.h>
|
2009-01-13 15:55:13 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2009-01-19 19:27:36 +00:00
|
|
|
#include <sys/time.h>
|
2009-01-14 17:10:52 +00:00
|
|
|
#include <sys/stat.h>
|
2009-01-13 15:55:13 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/queue.h>
|
2009-01-14 17:10:52 +00:00
|
|
|
#include <sys/param.h>
|
2009-01-19 19:27:36 +00:00
|
|
|
#include <sys/select.h>
|
2012-02-10 19:31:11 -06:00
|
|
|
#if defined(__linux__)
|
2012-02-11 09:42:01 +08:00
|
|
|
#include "tree.h"
|
2012-02-10 19:31:11 -06:00
|
|
|
#elif defined(__OpenBSD__)
|
2012-02-09 17:19:00 +00:00
|
|
|
#include <sys/tree.h>
|
2012-02-11 09:42:01 +08:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <sys/tree.h>
|
|
|
|
#else
|
2012-02-16 09:22:47 -06:00
|
|
|
#include "tree.h"
|
2012-02-11 09:42:01 +08:00
|
|
|
#endif
|
2009-01-13 15:55:13 +00:00
|
|
|
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
#include <X11/keysym.h>
|
2012-05-16 00:22:59 -04:00
|
|
|
#include <X11/XKBlib.h>
|
2009-01-13 15:55:13 +00:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/Xutil.h>
|
2009-01-19 05:48:11 +00:00
|
|
|
#include <X11/extensions/Xrandr.h>
|
2011-08-08 22:41:51 +00:00
|
|
|
#include <X11/extensions/XTest.h>
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-11-25 16:12:13 +00:00
|
|
|
#ifdef __OSX__
|
|
|
|
#include <osx.h>
|
|
|
|
#endif
|
|
|
|
|
2011-10-26 00:54:52 -04:00
|
|
|
#include "version.h"
|
|
|
|
|
2012-02-15 14:09:13 -06:00
|
|
|
#ifdef SPECTRWM_BUILDSTR
|
|
|
|
static const char *buildstr = SPECTRWM_BUILDSTR;
|
2011-10-26 00:54:52 -04:00
|
|
|
#else
|
2012-02-15 14:09:13 -06:00
|
|
|
static const char *buildstr = SPECTRWM_VERSION;
|
2011-10-26 00:54:52 -04:00
|
|
|
#endif
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
#if RANDR_MAJOR < 1
|
|
|
|
# error XRandR versions less than 1.0 are not supported
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RANDR_MAJOR >= 1
|
|
|
|
#if RANDR_MINOR >= 2
|
|
|
|
#define SWM_XRR_HAS_CRTC
|
|
|
|
#endif
|
|
|
|
#endif
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2011-06-08 19:05:43 +00:00
|
|
|
/*#define SWM_DEBUG*/
|
2009-01-13 15:55:13 +00:00
|
|
|
#ifdef SWM_DEBUG
|
2009-10-02 03:28:46 +00:00
|
|
|
#define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0)
|
|
|
|
#define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0)
|
2012-02-11 09:45:09 +08:00
|
|
|
#define SWM_D_MISC 0x0001
|
|
|
|
#define SWM_D_EVENT 0x0002
|
|
|
|
#define SWM_D_WS 0x0004
|
|
|
|
#define SWM_D_FOCUS 0x0008
|
|
|
|
#define SWM_D_MOVE 0x0010
|
|
|
|
#define SWM_D_STACK 0x0020
|
|
|
|
#define SWM_D_MOUSE 0x0040
|
|
|
|
#define SWM_D_PROP 0x0080
|
|
|
|
#define SWM_D_CLASS 0x0100
|
2009-03-10 01:32:06 +00:00
|
|
|
#define SWM_D_KEY 0x0200
|
2009-05-25 22:04:56 +00:00
|
|
|
#define SWM_D_QUIRK 0x0400
|
2009-09-12 21:32:21 +00:00
|
|
|
#define SWM_D_SPAWN 0x0800
|
2009-09-25 19:25:29 +00:00
|
|
|
#define SWM_D_EVENTQ 0x1000
|
|
|
|
#define SWM_D_CONF 0x2000
|
2012-02-02 07:00:45 +08:00
|
|
|
#define SWM_D_BAR 0x4000
|
2009-01-24 17:57:26 +00:00
|
|
|
|
2009-01-15 02:14:08 +00:00
|
|
|
u_int32_t swm_debug = 0
|
2009-01-15 06:41:06 +00:00
|
|
|
| SWM_D_MISC
|
2009-01-13 15:55:13 +00:00
|
|
|
| SWM_D_EVENT
|
|
|
|
| SWM_D_WS
|
2009-01-13 22:51:20 +00:00
|
|
|
| SWM_D_FOCUS
|
2009-01-15 06:41:06 +00:00
|
|
|
| SWM_D_MOVE
|
2009-01-19 05:48:11 +00:00
|
|
|
| SWM_D_STACK
|
2009-01-28 20:58:39 +00:00
|
|
|
| SWM_D_MOUSE
|
2009-01-24 17:57:26 +00:00
|
|
|
| SWM_D_PROP
|
2009-01-29 20:27:11 +00:00
|
|
|
| SWM_D_CLASS
|
2009-03-10 01:32:06 +00:00
|
|
|
| SWM_D_KEY
|
2009-05-25 22:04:56 +00:00
|
|
|
| SWM_D_QUIRK
|
2009-09-12 21:32:21 +00:00
|
|
|
| SWM_D_SPAWN
|
2009-09-25 19:25:29 +00:00
|
|
|
| SWM_D_EVENTQ
|
|
|
|
| SWM_D_CONF
|
2012-02-02 07:00:45 +08:00
|
|
|
| SWM_D_BAR
|
2009-01-13 15:55:13 +00:00
|
|
|
;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x...)
|
|
|
|
#define DNPRINTF(n,x...)
|
|
|
|
#endif
|
|
|
|
|
2009-01-22 03:46:13 +00:00
|
|
|
#define LENGTH(x) (sizeof x / sizeof x[0])
|
2009-01-13 15:55:13 +00:00
|
|
|
#define MODKEY Mod1Mask
|
2009-01-22 03:46:13 +00:00
|
|
|
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
|
|
|
|
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
|
2009-01-29 21:38:49 +00:00
|
|
|
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
2009-01-28 20:58:39 +00:00
|
|
|
#define SWM_PROPLEN (16)
|
2009-03-10 01:32:06 +00:00
|
|
|
#define SWM_FUNCNAME_LEN (32)
|
|
|
|
#define SWM_KEYS_LEN (255)
|
2009-08-01 19:59:12 +00:00
|
|
|
#define SWM_QUIRK_LEN (64)
|
2009-02-03 05:08:27 +00:00
|
|
|
#define X(r) (r)->g.x
|
2009-01-28 20:58:39 +00:00
|
|
|
#define Y(r) (r)->g.y
|
2009-02-03 05:08:27 +00:00
|
|
|
#define WIDTH(r) (r)->g.w
|
2009-01-28 20:58:39 +00:00
|
|
|
#define HEIGHT(r) (r)->g.h
|
2012-02-04 01:58:52 +08:00
|
|
|
#define SH_MIN(w) (w)->sh_mask & PMinSize
|
|
|
|
#define SH_MIN_W(w) (w)->sh.min_width
|
|
|
|
#define SH_MIN_H(w) (w)->sh.min_height
|
|
|
|
#define SH_MAX(w) (w)->sh_mask & PMaxSize
|
|
|
|
#define SH_MAX_W(w) (w)->sh.max_width
|
|
|
|
#define SH_MAX_H(w) (w)->sh.max_height
|
|
|
|
#define SH_INC(w) (w)->sh_mask & PResizeInc
|
|
|
|
#define SH_INC_W(w) (w)->sh.width_inc
|
|
|
|
#define SH_INC_H(w) (w)->sh.height_inc
|
2009-02-07 19:49:58 +00:00
|
|
|
#define SWM_MAX_FONT_STEPS (3)
|
2012-02-04 01:58:52 +08:00
|
|
|
#define WINID(w) ((w) ? (w)->id : 0)
|
|
|
|
#define YESNO(x) ((x) ? "yes" : "no")
|
2009-01-18 00:28:20 +00:00
|
|
|
|
2010-06-30 00:09:19 +00:00
|
|
|
#define SWM_FOCUS_DEFAULT (0)
|
|
|
|
#define SWM_FOCUS_SYNERGY (1)
|
|
|
|
#define SWM_FOCUS_FOLLOW (2)
|
|
|
|
|
2011-10-25 22:40:12 -04:00
|
|
|
#define SWM_CONF_DEFAULT (0)
|
|
|
|
#define SWM_CONF_KEYMAPPING (1)
|
|
|
|
|
2009-01-24 17:57:26 +00:00
|
|
|
#ifndef SWM_LIB
|
2009-09-26 16:40:08 +00:00
|
|
|
#define SWM_LIB "/usr/local/lib/libswmhack.so"
|
2009-01-24 17:57:26 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-17 17:23:52 +00:00
|
|
|
char **start_argv;
|
2009-01-17 19:57:48 +00:00
|
|
|
Atom astate;
|
2009-02-10 18:16:10 +00:00
|
|
|
Atom aprot;
|
|
|
|
Atom adelete;
|
2009-10-07 02:38:38 +00:00
|
|
|
Atom takefocus;
|
2011-06-06 19:52:03 +00:00
|
|
|
Atom a_wmname;
|
2012-01-15 14:53:00 -05:00
|
|
|
Atom a_netwmname;
|
2011-06-06 19:52:03 +00:00
|
|
|
Atom a_utf8_string;
|
|
|
|
Atom a_string;
|
|
|
|
Atom a_swm_iconic;
|
2009-09-29 14:25:40 +00:00
|
|
|
volatile sig_atomic_t running = 1;
|
2010-07-03 22:41:34 +00:00
|
|
|
volatile sig_atomic_t restart_wm = 0;
|
2009-09-29 18:59:09 +00:00
|
|
|
int outputs = 0;
|
2009-10-30 01:56:00 +00:00
|
|
|
int last_focus_event = FocusOut;
|
2009-01-13 15:55:13 +00:00
|
|
|
int (*xerrorxlib)(Display *, XErrorEvent *);
|
|
|
|
int other_wm;
|
2009-01-25 01:46:44 +00:00
|
|
|
int ss_enabled = 0;
|
2009-02-03 05:08:27 +00:00
|
|
|
int xrandr_support;
|
2009-01-19 05:48:11 +00:00
|
|
|
int xrandr_eventbase;
|
2009-01-13 15:55:13 +00:00
|
|
|
unsigned int numlockmask = 0;
|
|
|
|
Display *display;
|
|
|
|
|
2009-01-21 01:26:56 +00:00
|
|
|
int cycle_empty = 0;
|
|
|
|
int cycle_visible = 0;
|
2009-02-07 19:49:58 +00:00
|
|
|
int term_width = 0;
|
|
|
|
int font_adjusted = 0;
|
2009-08-11 16:20:55 +00:00
|
|
|
unsigned int mod_key = MODKEY;
|
2009-01-21 01:26:56 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
/* dmenu search */
|
|
|
|
struct swm_region *search_r;
|
|
|
|
int select_list_pipe[2];
|
|
|
|
int select_resp_pipe[2];
|
|
|
|
pid_t searchpid;
|
|
|
|
volatile sig_atomic_t search_resp;
|
2011-11-28 23:15:28 -05:00
|
|
|
int search_resp_action;
|
|
|
|
|
2011-11-28 23:41:37 -05:00
|
|
|
struct search_window {
|
|
|
|
TAILQ_ENTRY(search_window) entry;
|
2012-01-29 01:29:31 +08:00
|
|
|
int idx;
|
|
|
|
struct ws_win *win;
|
2012-02-02 07:00:45 +08:00
|
|
|
GC gc;
|
2011-11-28 23:41:37 -05:00
|
|
|
Window indicator;
|
|
|
|
};
|
|
|
|
TAILQ_HEAD(search_winlist, search_window);
|
2012-05-12 21:28:49 +01:00
|
|
|
struct search_winlist search_wl;
|
2011-11-28 23:41:37 -05:00
|
|
|
|
2011-11-28 23:15:28 -05:00
|
|
|
/* search actions */
|
|
|
|
enum {
|
|
|
|
SWM_SEARCH_NONE,
|
2011-11-28 23:25:46 -05:00
|
|
|
SWM_SEARCH_UNICONIFY,
|
|
|
|
SWM_SEARCH_NAME_WORKSPACE,
|
2011-11-28 23:41:37 -05:00
|
|
|
SWM_SEARCH_SEARCH_WORKSPACE,
|
|
|
|
SWM_SEARCH_SEARCH_WINDOW
|
2011-11-28 23:15:28 -05:00
|
|
|
};
|
2011-06-06 19:52:03 +00:00
|
|
|
|
2012-05-23 18:31:11 +08:00
|
|
|
#define SWM_STACK_TOP (0)
|
|
|
|
#define SWM_STACK_BOTTOM (1)
|
|
|
|
#define SWM_STACK_ABOVE (2)
|
|
|
|
#define SWM_STACK_BELOW (3)
|
|
|
|
|
2009-01-18 04:48:04 +00:00
|
|
|
/* dialog windows */
|
2012-02-02 07:00:45 +08:00
|
|
|
double dialog_ratio = 0.6;
|
2009-01-14 04:44:58 +00:00
|
|
|
/* status bar */
|
2011-11-28 22:31:11 -05:00
|
|
|
#define SWM_BAR_MAX (256)
|
|
|
|
#define SWM_BAR_JUSTIFY_LEFT (0)
|
|
|
|
#define SWM_BAR_JUSTIFY_CENTER (1)
|
|
|
|
#define SWM_BAR_JUSTIFY_RIGHT (2)
|
|
|
|
#define SWM_BAR_OFFSET (4)
|
2012-02-02 07:00:45 +08:00
|
|
|
#define SWM_BAR_FONTS "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*," \
|
|
|
|
"-*-profont-*-*-*-*-*-*-*-*-*-*-*-*," \
|
|
|
|
"-*-times-medium-r-*-*-*-*-*-*-*-*-*-*," \
|
2012-05-26 18:14:23 +08:00
|
|
|
"-misc-fixed-medium-r-*-*-*-*-*-*-*-*-*-*," \
|
|
|
|
"-*-*-*-r-*--*-*-*-*-*-*-*-*"
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
#ifdef X_HAVE_UTF8_STRING
|
|
|
|
#define DRAWSTRING(x...) Xutf8DrawString(x)
|
|
|
|
#else
|
|
|
|
#define DRAWSTRING(x...) XmbDrawString(x)
|
|
|
|
#endif
|
|
|
|
|
2009-01-22 17:50:16 +00:00
|
|
|
char *bar_argv[] = { NULL, NULL };
|
|
|
|
int bar_pipe[2];
|
2012-02-02 07:00:45 +08:00
|
|
|
unsigned char bar_ext[SWM_BAR_MAX];
|
2009-01-30 20:16:01 +00:00
|
|
|
char bar_vertext[SWM_BAR_MAX];
|
|
|
|
int bar_version = 0;
|
2009-01-19 19:27:36 +00:00
|
|
|
sig_atomic_t bar_alarm = 0;
|
2009-01-23 22:50:38 +00:00
|
|
|
int bar_delay = 30;
|
2009-01-14 04:44:58 +00:00
|
|
|
int bar_enabled = 1;
|
2011-03-11 21:34:19 +00:00
|
|
|
int bar_border_width = 1;
|
2010-07-15 14:03:04 +00:00
|
|
|
int bar_at_bottom = 0;
|
2009-01-22 17:50:16 +00:00
|
|
|
int bar_extra = 1;
|
|
|
|
int bar_extra_running = 0;
|
2009-01-19 21:11:46 +00:00
|
|
|
int bar_verbose = 1;
|
2009-01-14 17:10:52 +00:00
|
|
|
int bar_height = 0;
|
2011-11-28 22:31:11 -05:00
|
|
|
int bar_justify = SWM_BAR_JUSTIFY_LEFT;
|
2012-05-13 01:33:38 +01:00
|
|
|
char *bar_format = NULL;
|
2009-10-02 19:50:05 +00:00
|
|
|
int stack_enabled = 1;
|
2009-02-18 20:34:26 +00:00
|
|
|
int clock_enabled = 1;
|
2011-08-06 18:21:00 +00:00
|
|
|
int urgent_enabled = 0;
|
2010-01-13 21:48:35 +00:00
|
|
|
char *clock_format = NULL;
|
2009-06-04 06:03:37 +00:00
|
|
|
int title_name_enabled = 0;
|
|
|
|
int title_class_enabled = 0;
|
2011-01-18 19:43:12 +00:00
|
|
|
int window_name_enabled = 0;
|
2010-06-30 00:09:19 +00:00
|
|
|
int focus_mode = SWM_FOCUS_DEFAULT;
|
2012-05-23 18:31:11 +08:00
|
|
|
int focus_close = SWM_STACK_BELOW;
|
|
|
|
int focus_close_wrap = 1;
|
|
|
|
int focus_default = SWM_STACK_TOP;
|
|
|
|
int spawn_position = SWM_STACK_TOP;
|
2010-07-01 23:44:16 +00:00
|
|
|
int disable_border = 0;
|
2011-03-11 14:12:49 +00:00
|
|
|
int border_width = 1;
|
2011-07-19 21:28:15 +00:00
|
|
|
int verbose_layout = 0;
|
2009-01-22 17:50:16 +00:00
|
|
|
pid_t bar_pid;
|
2012-02-02 07:00:45 +08:00
|
|
|
XFontSet bar_fs;
|
|
|
|
XFontSetExtents *bar_fs_extents;
|
|
|
|
char *bar_fonts;
|
|
|
|
char *spawn_term[] = { NULL, NULL }; /* XXX fully dynamic */
|
2011-10-25 22:40:12 -04:00
|
|
|
struct passwd *pwd;
|
2009-01-22 06:21:23 +00:00
|
|
|
|
|
|
|
#define SWM_MENU_FN (2)
|
|
|
|
#define SWM_MENU_NB (4)
|
|
|
|
#define SWM_MENU_NF (6)
|
|
|
|
#define SWM_MENU_SB (8)
|
|
|
|
#define SWM_MENU_SF (10)
|
2009-01-14 04:44:58 +00:00
|
|
|
|
2009-01-15 13:59:58 +00:00
|
|
|
/* layout manager data */
|
2009-01-16 05:25:13 +00:00
|
|
|
struct swm_geometry {
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
};
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_screen;
|
|
|
|
struct workspace;
|
|
|
|
|
|
|
|
/* virtual "screens" */
|
|
|
|
struct swm_region {
|
|
|
|
TAILQ_ENTRY(swm_region) entry;
|
|
|
|
struct swm_geometry g;
|
2009-08-30 18:16:41 +00:00
|
|
|
struct workspace *ws; /* current workspace on this region */
|
2010-07-01 19:01:15 +00:00
|
|
|
struct workspace *ws_prior; /* prior workspace on this region */
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_screen *s; /* screen idx */
|
2009-02-01 11:59:40 +00:00
|
|
|
Window bar_window;
|
2009-08-30 18:16:41 +00:00
|
|
|
};
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_HEAD(swm_region_list, swm_region);
|
|
|
|
|
2009-01-16 10:02:13 +00:00
|
|
|
struct ws_win {
|
|
|
|
TAILQ_ENTRY(ws_win) entry;
|
|
|
|
Window id;
|
2009-10-07 02:38:38 +00:00
|
|
|
Window transient;
|
|
|
|
struct ws_win *child_trans; /* transient child window */
|
2010-07-01 20:58:00 +00:00
|
|
|
struct swm_geometry g; /* current geometry */
|
|
|
|
struct swm_geometry g_float; /* geometry when floating */
|
|
|
|
struct swm_geometry rg_float; /* region geom when floating */
|
2012-01-29 01:29:31 +08:00
|
|
|
int g_floatvalid; /* g_float geometry validity */
|
|
|
|
int floatmaxed; /* whether maxed by max_stack */
|
2009-01-16 10:02:13 +00:00
|
|
|
int floating;
|
2009-02-01 01:39:25 +00:00
|
|
|
int manual;
|
2011-06-06 19:52:03 +00:00
|
|
|
int iconic;
|
2010-09-16 02:26:45 +00:00
|
|
|
unsigned int ewmh_flags;
|
2009-02-07 19:49:58 +00:00
|
|
|
int font_size_boundary[SWM_MAX_FONT_STEPS];
|
|
|
|
int font_steps;
|
|
|
|
int last_inc;
|
2009-02-10 18:16:10 +00:00
|
|
|
int can_delete;
|
2009-10-07 02:38:38 +00:00
|
|
|
int take_focus;
|
2009-10-06 17:04:53 +00:00
|
|
|
int java;
|
2009-02-03 00:50:01 +00:00
|
|
|
unsigned long quirks;
|
2009-01-19 05:48:11 +00:00
|
|
|
struct workspace *ws; /* always valid */
|
|
|
|
struct swm_screen *s; /* always valid, never changes */
|
2009-01-16 10:02:13 +00:00
|
|
|
XWindowAttributes wa;
|
2009-01-25 17:56:01 +00:00
|
|
|
XSizeHints sh;
|
2012-02-04 01:58:52 +08:00
|
|
|
long sh_mask;
|
2009-01-29 20:35:01 +00:00
|
|
|
XClassHint ch;
|
2011-06-10 20:11:11 +00:00
|
|
|
XWMHints *hints;
|
2009-01-16 10:02:13 +00:00
|
|
|
};
|
|
|
|
TAILQ_HEAD(ws_win_list, ws_win);
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
/* pid goo */
|
|
|
|
struct pid_e {
|
|
|
|
TAILQ_ENTRY(pid_e) entry;
|
|
|
|
long pid;
|
|
|
|
int ws;
|
|
|
|
};
|
|
|
|
TAILQ_HEAD(pid_list, pid_e);
|
|
|
|
struct pid_list pidlist = TAILQ_HEAD_INITIALIZER(pidlist);
|
|
|
|
|
2009-01-16 10:02:13 +00:00
|
|
|
/* layout handlers */
|
2009-01-15 13:59:58 +00:00
|
|
|
void stack(void);
|
2009-01-20 05:37:45 +00:00
|
|
|
void vertical_config(struct workspace *, int);
|
2009-01-19 05:48:11 +00:00
|
|
|
void vertical_stack(struct workspace *, struct swm_geometry *);
|
2009-01-20 05:37:45 +00:00
|
|
|
void horizontal_config(struct workspace *, int);
|
2009-01-19 05:48:11 +00:00
|
|
|
void horizontal_stack(struct workspace *, struct swm_geometry *);
|
|
|
|
void max_stack(struct workspace *, struct swm_geometry *);
|
2011-07-19 21:28:15 +00:00
|
|
|
void plain_stacker(struct workspace *);
|
|
|
|
void fancy_stacker(struct workspace *);
|
2009-01-15 13:59:58 +00:00
|
|
|
|
2009-10-15 22:18:45 +00:00
|
|
|
struct ws_win *find_window(Window);
|
|
|
|
|
2009-01-22 03:46:13 +00:00
|
|
|
void grabbuttons(struct ws_win *, int);
|
2009-02-12 22:09:44 +00:00
|
|
|
void new_region(struct swm_screen *, int, int, int, int);
|
2009-10-05 17:03:47 +00:00
|
|
|
void unmanage_window(struct ws_win *);
|
2009-10-13 02:28:47 +00:00
|
|
|
long getstate(Window);
|
2009-01-22 03:46:13 +00:00
|
|
|
|
2011-10-25 22:40:12 -04:00
|
|
|
int conf_load(char *, int);
|
|
|
|
|
2009-01-15 13:59:58 +00:00
|
|
|
struct layout {
|
2009-01-19 05:48:11 +00:00
|
|
|
void (*l_stack)(struct workspace *, struct swm_geometry *);
|
2009-01-20 05:37:45 +00:00
|
|
|
void (*l_config)(struct workspace *, int);
|
2009-10-02 15:40:43 +00:00
|
|
|
u_int32_t flags;
|
2011-06-13 20:28:04 +00:00
|
|
|
#define SWM_L_FOCUSPREV (1<<0)
|
2009-10-16 04:28:40 +00:00
|
|
|
#define SWM_L_MAPONFOCUS (1<<1)
|
2011-07-19 21:28:15 +00:00
|
|
|
void (*l_string)(struct workspace *);
|
2009-01-15 13:59:58 +00:00
|
|
|
} layouts[] = {
|
2009-01-20 05:37:45 +00:00
|
|
|
/* stack, configure */
|
2011-08-06 18:21:00 +00:00
|
|
|
{ vertical_stack, vertical_config, 0, plain_stacker },
|
|
|
|
{ horizontal_stack, horizontal_config, 0, plain_stacker },
|
2009-10-02 15:40:43 +00:00
|
|
|
{ max_stack, NULL,
|
2011-08-06 18:21:00 +00:00
|
|
|
SWM_L_MAPONFOCUS | SWM_L_FOCUSPREV, plain_stacker },
|
2011-06-14 22:20:55 +00:00
|
|
|
{ NULL, NULL, 0, NULL },
|
2009-01-15 13:59:58 +00:00
|
|
|
};
|
|
|
|
|
2011-06-23 17:52:39 +00:00
|
|
|
/* position of max_stack mode in the layouts array, index into layouts! */
|
|
|
|
#define SWM_V_STACK (0)
|
|
|
|
#define SWM_H_STACK (1)
|
|
|
|
#define SWM_MAX_STACK (2)
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
#define SWM_H_SLICE (32)
|
|
|
|
#define SWM_V_SLICE (32)
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
/* define work spaces */
|
|
|
|
struct workspace {
|
2009-01-19 05:48:11 +00:00
|
|
|
int idx; /* workspace index */
|
2011-11-28 23:25:46 -05:00
|
|
|
char *name; /* workspace name */
|
2011-06-24 16:53:40 +00:00
|
|
|
int always_raise; /* raise windows on focus */
|
2009-01-15 13:59:58 +00:00
|
|
|
struct layout *cur_layout; /* current layout handlers */
|
2009-01-19 05:48:11 +00:00
|
|
|
struct ws_win *focus; /* may be NULL */
|
2009-02-07 19:21:00 +00:00
|
|
|
struct ws_win *focus_prev; /* may be NULL */
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_region *r; /* may be NULL */
|
2009-10-01 09:51:31 +00:00
|
|
|
struct swm_region *old_r; /* may be NULL */
|
2009-01-14 05:48:18 +00:00
|
|
|
struct ws_win_list winlist; /* list of windows in ws */
|
2009-10-13 02:28:47 +00:00
|
|
|
struct ws_win_list unmanagedlist; /* list of dead windows in ws */
|
2011-07-19 21:28:15 +00:00
|
|
|
char stacker[10]; /* display stacker and layout */
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
/* stacker state */
|
|
|
|
struct {
|
|
|
|
int horizontal_msize;
|
2009-01-20 05:37:45 +00:00
|
|
|
int horizontal_mwin;
|
2009-02-03 13:13:30 +00:00
|
|
|
int horizontal_stacks;
|
2012-02-08 01:17:20 +08:00
|
|
|
int horizontal_flip;
|
2009-01-19 05:48:11 +00:00
|
|
|
int vertical_msize;
|
2009-01-20 05:37:45 +00:00
|
|
|
int vertical_mwin;
|
2009-02-03 13:13:30 +00:00
|
|
|
int vertical_stacks;
|
2012-02-08 01:17:20 +08:00
|
|
|
int vertical_flip;
|
2009-01-19 05:48:11 +00:00
|
|
|
} l_state;
|
|
|
|
};
|
|
|
|
|
2009-01-22 06:21:23 +00:00
|
|
|
enum { SWM_S_COLOR_BAR, SWM_S_COLOR_BAR_BORDER, SWM_S_COLOR_BAR_FONT,
|
|
|
|
SWM_S_COLOR_FOCUS, SWM_S_COLOR_UNFOCUS, SWM_S_COLOR_MAX };
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
/* physical screen mapping */
|
2012-04-08 01:59:41 +08:00
|
|
|
#define SWM_WS_MAX (22) /* hard limit */
|
|
|
|
int workspace_limit = 10; /* soft limit */
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_screen {
|
2009-10-14 13:56:02 +00:00
|
|
|
int idx; /* screen index */
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_region_list rl; /* list of regions on this screen */
|
2009-02-03 05:08:27 +00:00
|
|
|
struct swm_region_list orl; /* list of old regions */
|
2009-01-19 05:48:11 +00:00
|
|
|
Window root;
|
|
|
|
struct workspace ws[SWM_WS_MAX];
|
|
|
|
|
|
|
|
/* colors */
|
2009-01-22 06:21:23 +00:00
|
|
|
struct {
|
|
|
|
unsigned long color;
|
|
|
|
char *name;
|
|
|
|
} c[SWM_S_COLOR_MAX];
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
GC bar_gc;
|
2009-01-19 05:48:11 +00:00
|
|
|
};
|
|
|
|
struct swm_screen *screens;
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
/* args to functions */
|
|
|
|
union arg {
|
2009-01-13 22:59:00 +00:00
|
|
|
int id;
|
2009-01-13 15:55:13 +00:00
|
|
|
#define SWM_ARG_ID_FOCUSNEXT (0)
|
|
|
|
#define SWM_ARG_ID_FOCUSPREV (1)
|
|
|
|
#define SWM_ARG_ID_FOCUSMAIN (2)
|
2009-10-15 20:42:59 +00:00
|
|
|
#define SWM_ARG_ID_FOCUSCUR (4)
|
|
|
|
#define SWM_ARG_ID_SWAPNEXT (10)
|
|
|
|
#define SWM_ARG_ID_SWAPPREV (11)
|
|
|
|
#define SWM_ARG_ID_SWAPMAIN (12)
|
2010-07-01 20:58:00 +00:00
|
|
|
#define SWM_ARG_ID_MOVELAST (13)
|
2009-10-15 20:42:59 +00:00
|
|
|
#define SWM_ARG_ID_MASTERSHRINK (20)
|
|
|
|
#define SWM_ARG_ID_MASTERGROW (21)
|
|
|
|
#define SWM_ARG_ID_MASTERADD (22)
|
|
|
|
#define SWM_ARG_ID_MASTERDEL (23)
|
2012-02-08 01:17:20 +08:00
|
|
|
#define SWM_ARG_ID_FLIPLAYOUT (24)
|
2009-10-15 20:42:59 +00:00
|
|
|
#define SWM_ARG_ID_STACKRESET (30)
|
|
|
|
#define SWM_ARG_ID_STACKINIT (31)
|
|
|
|
#define SWM_ARG_ID_CYCLEWS_UP (40)
|
|
|
|
#define SWM_ARG_ID_CYCLEWS_DOWN (41)
|
|
|
|
#define SWM_ARG_ID_CYCLESC_UP (42)
|
|
|
|
#define SWM_ARG_ID_CYCLESC_DOWN (43)
|
2011-11-28 22:41:58 -05:00
|
|
|
#define SWM_ARG_ID_CYCLEWS_UP_ALL (44)
|
|
|
|
#define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45)
|
2009-10-15 20:42:59 +00:00
|
|
|
#define SWM_ARG_ID_STACKINC (50)
|
|
|
|
#define SWM_ARG_ID_STACKDEC (51)
|
|
|
|
#define SWM_ARG_ID_SS_ALL (60)
|
|
|
|
#define SWM_ARG_ID_SS_WINDOW (61)
|
|
|
|
#define SWM_ARG_ID_DONTCENTER (70)
|
|
|
|
#define SWM_ARG_ID_CENTER (71)
|
|
|
|
#define SWM_ARG_ID_KILLWINDOW (80)
|
|
|
|
#define SWM_ARG_ID_DELETEWINDOW (81)
|
2011-10-03 16:39:12 -05:00
|
|
|
#define SWM_ARG_ID_WIDTHGROW (90)
|
|
|
|
#define SWM_ARG_ID_WIDTHSHRINK (91)
|
|
|
|
#define SWM_ARG_ID_HEIGHTGROW (92)
|
|
|
|
#define SWM_ARG_ID_HEIGHTSHRINK (93)
|
|
|
|
#define SWM_ARG_ID_MOVEUP (100)
|
|
|
|
#define SWM_ARG_ID_MOVEDOWN (101)
|
|
|
|
#define SWM_ARG_ID_MOVELEFT (102)
|
|
|
|
#define SWM_ARG_ID_MOVERIGHT (103)
|
2009-01-13 22:59:00 +00:00
|
|
|
char **argv;
|
2009-01-13 15:55:13 +00:00
|
|
|
};
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
void focus(struct swm_region *, union arg *);
|
2011-06-07 20:56:29 +00:00
|
|
|
void focus_magic(struct ws_win *);
|
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
/* quirks */
|
2009-01-29 20:27:11 +00:00
|
|
|
struct quirk {
|
2012-02-02 21:44:21 +00:00
|
|
|
TAILQ_ENTRY(quirk) entry;
|
2009-08-11 16:20:55 +00:00
|
|
|
char *class;
|
|
|
|
char *name;
|
2009-01-29 20:27:11 +00:00
|
|
|
unsigned long quirk;
|
2009-02-03 21:50:16 +00:00
|
|
|
#define SWM_Q_FLOAT (1<<0) /* float this window */
|
|
|
|
#define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */
|
|
|
|
#define SWM_Q_ANYWHERE (1<<2) /* don't position this window */
|
2009-02-07 19:49:58 +00:00
|
|
|
#define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */
|
2009-02-11 06:02:24 +00:00
|
|
|
#define SWM_Q_FULLSCREEN (1<<4) /* remove border */
|
2011-06-13 20:28:04 +00:00
|
|
|
#define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
|
2009-01-29 20:27:11 +00:00
|
|
|
};
|
2012-02-02 21:44:21 +00:00
|
|
|
TAILQ_HEAD(quirk_list, quirk);
|
2012-02-02 23:25:29 +00:00
|
|
|
struct quirk_list quirks = TAILQ_HEAD_INITIALIZER(quirks);
|
2009-01-29 20:27:11 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
/*
|
|
|
|
* Supported EWMH hints should be added to
|
|
|
|
* both the enum and the ewmh array
|
|
|
|
*/
|
|
|
|
enum { _NET_ACTIVE_WINDOW, _NET_MOVERESIZE_WINDOW, _NET_CLOSE_WINDOW,
|
|
|
|
_NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DOCK,
|
|
|
|
_NET_WM_WINDOW_TYPE_TOOLBAR, _NET_WM_WINDOW_TYPE_UTILITY,
|
|
|
|
_NET_WM_WINDOW_TYPE_SPLASH, _NET_WM_WINDOW_TYPE_DIALOG,
|
|
|
|
_NET_WM_WINDOW_TYPE_NORMAL, _NET_WM_STATE,
|
|
|
|
_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT,
|
|
|
|
_NET_WM_STATE_SKIP_TASKBAR, _NET_WM_STATE_SKIP_PAGER,
|
|
|
|
_NET_WM_STATE_HIDDEN, _NET_WM_STATE_ABOVE, _SWM_WM_STATE_MANUAL,
|
|
|
|
_NET_WM_STATE_FULLSCREEN, _NET_WM_ALLOWED_ACTIONS, _NET_WM_ACTION_MOVE,
|
|
|
|
_NET_WM_ACTION_RESIZE, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_CLOSE,
|
|
|
|
SWM_EWMH_HINT_MAX };
|
|
|
|
|
|
|
|
struct ewmh_hint {
|
|
|
|
char *name;
|
|
|
|
Atom atom;
|
|
|
|
} ewmh[SWM_EWMH_HINT_MAX] = {
|
|
|
|
/* must be in same order as in the enum */
|
|
|
|
{"_NET_ACTIVE_WINDOW", None},
|
|
|
|
{"_NET_MOVERESIZE_WINDOW", None},
|
|
|
|
{"_NET_CLOSE_WINDOW", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_DOCK", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_TOOLBAR", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_UTILITY", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_SPLASH", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_DIALOG", None},
|
|
|
|
{"_NET_WM_WINDOW_TYPE_NORMAL", None},
|
|
|
|
{"_NET_WM_STATE", None},
|
|
|
|
{"_NET_WM_STATE_MAXIMIZED_HORZ", None},
|
|
|
|
{"_NET_WM_STATE_MAXIMIZED_VERT", None},
|
|
|
|
{"_NET_WM_STATE_SKIP_TASKBAR", None},
|
|
|
|
{"_NET_WM_STATE_SKIP_PAGER", None},
|
|
|
|
{"_NET_WM_STATE_HIDDEN", None},
|
|
|
|
{"_NET_WM_STATE_ABOVE", None},
|
|
|
|
{"_SWM_WM_STATE_MANUAL", None},
|
|
|
|
{"_NET_WM_STATE_FULLSCREEN", None},
|
|
|
|
{"_NET_WM_ALLOWED_ACTIONS", None},
|
|
|
|
{"_NET_WM_ACTION_MOVE", None},
|
|
|
|
{"_NET_WM_ACTION_RESIZE", None},
|
|
|
|
{"_NET_WM_ACTION_FULLSCREEN", None},
|
|
|
|
{"_NET_WM_ACTION_CLOSE", None},
|
|
|
|
};
|
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
void store_float_geom(struct ws_win *, struct swm_region *);
|
|
|
|
int floating_toggle_win(struct ws_win *);
|
|
|
|
void spawn_select(struct swm_region *, union arg *, char *, int *);
|
2012-02-04 14:25:40 +00:00
|
|
|
unsigned char *get_win_name(Window);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
int
|
2012-02-04 14:41:30 +00:00
|
|
|
get_property(Window id, Atom atom, long count, Atom type, unsigned long *nitems,
|
|
|
|
unsigned long *nbytes, unsigned char **data)
|
2010-09-16 02:26:45 +00:00
|
|
|
{
|
|
|
|
int format, status;
|
2012-02-04 14:41:30 +00:00
|
|
|
unsigned long *nbytes_ret, *nitems_ret;
|
|
|
|
unsigned long nbytes_tmp, nitems_tmp;
|
2010-09-16 02:26:45 +00:00
|
|
|
Atom real;
|
|
|
|
|
2012-02-04 14:41:30 +00:00
|
|
|
nbytes_ret = nbytes != NULL ? nbytes : &nbytes_tmp;
|
|
|
|
nitems_ret = nitems != NULL ? nitems : &nitems_tmp;
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
status = XGetWindowProperty(display, id, atom, 0L, count, False, type,
|
2012-02-04 14:41:30 +00:00
|
|
|
&real, &format, nitems_ret, nbytes_ret, data);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (status != Success)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (False);
|
2010-09-16 02:26:45 +00:00
|
|
|
if (real != type)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (False);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2012-05-12 21:28:49 +01:00
|
|
|
return (True);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
void
|
|
|
|
update_iconic(struct ws_win *win, int newv)
|
|
|
|
{
|
|
|
|
int32_t v = newv;
|
|
|
|
Atom iprop;
|
|
|
|
|
|
|
|
win->iconic = newv;
|
|
|
|
|
|
|
|
iprop = XInternAtom(display, "_SWM_ICONIC", False);
|
|
|
|
if (!iprop)
|
|
|
|
return;
|
|
|
|
if (newv)
|
|
|
|
XChangeProperty(display, win->id, iprop, XA_INTEGER, 32,
|
|
|
|
PropModeReplace, (unsigned char *)&v, 1);
|
|
|
|
else
|
|
|
|
XDeleteProperty(display, win->id, iprop);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
get_iconic(struct ws_win *win)
|
|
|
|
{
|
|
|
|
int32_t v = 0;
|
|
|
|
int retfmt, status;
|
|
|
|
Atom iprop, rettype;
|
|
|
|
unsigned long nitems, extra;
|
|
|
|
unsigned char *prop = NULL;
|
|
|
|
|
|
|
|
iprop = XInternAtom(display, "_SWM_ICONIC", False);
|
|
|
|
if (!iprop)
|
|
|
|
goto out;
|
|
|
|
status = XGetWindowProperty(display, win->id, iprop, 0L, 1L,
|
|
|
|
False, XA_INTEGER, &rettype, &retfmt, &nitems, &extra, &prop);
|
|
|
|
if (status != Success)
|
|
|
|
goto out;
|
|
|
|
if (rettype != XA_INTEGER || retfmt != 32)
|
|
|
|
goto out;
|
|
|
|
if (nitems != 1)
|
|
|
|
goto out;
|
|
|
|
v = *((int32_t *)prop);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (prop != NULL)
|
|
|
|
XFree(prop);
|
|
|
|
return (v);
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
void
|
|
|
|
setup_ewmh(void)
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
Atom sup_list;
|
|
|
|
|
|
|
|
sup_list = XInternAtom(display, "_NET_SUPPORTED", False);
|
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(ewmh); i++)
|
|
|
|
ewmh[i].atom = XInternAtom(display, ewmh[i].name, False);
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
/* Support check window will be created by workaround(). */
|
|
|
|
|
|
|
|
/* Report supported atoms */
|
|
|
|
XDeleteProperty(display, screens[i].root, sup_list);
|
|
|
|
for (j = 0; j < LENGTH(ewmh); j++)
|
2011-06-14 22:20:55 +00:00
|
|
|
XChangeProperty(display, screens[i].root,
|
|
|
|
sup_list, XA_ATOM, 32,
|
2012-05-12 21:28:49 +01:00
|
|
|
PropModeAppend, (unsigned char *)&ewmh[j].atom, 1);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
teardown_ewmh(void)
|
|
|
|
{
|
|
|
|
int i, success;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
unsigned long n;
|
|
|
|
Atom sup_check, sup_list;
|
|
|
|
Window id;
|
|
|
|
|
|
|
|
sup_check = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
|
|
|
|
sup_list = XInternAtom(display, "_NET_SUPPORTED", False);
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
/* Get the support check window and destroy it */
|
|
|
|
success = get_property(screens[i].root, sup_check, 1, XA_WINDOW,
|
2012-02-04 14:41:30 +00:00
|
|
|
&n, NULL, &data);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (success) {
|
|
|
|
id = data[0];
|
|
|
|
XDestroyWindow(display, id);
|
|
|
|
XDeleteProperty(display, screens[i].root, sup_check);
|
|
|
|
XDeleteProperty(display, screens[i].root, sup_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_autoquirk(struct ws_win *win)
|
|
|
|
{
|
|
|
|
int success, i;
|
2011-09-19 21:56:45 -05:00
|
|
|
unsigned long *data = NULL, n;
|
2010-09-16 02:26:45 +00:00
|
|
|
Atom type;
|
|
|
|
|
|
|
|
success = get_property(win->id, ewmh[_NET_WM_WINDOW_TYPE].atom, (~0L),
|
2012-02-04 14:41:30 +00:00
|
|
|
XA_ATOM, &n, NULL, (void *)&data);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
XFree(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
type = data[i];
|
|
|
|
if (type == ewmh[_NET_WM_WINDOW_TYPE_NORMAL].atom)
|
|
|
|
break;
|
|
|
|
if (type == ewmh[_NET_WM_WINDOW_TYPE_DOCK].atom ||
|
|
|
|
type == ewmh[_NET_WM_WINDOW_TYPE_TOOLBAR].atom ||
|
|
|
|
type == ewmh[_NET_WM_WINDOW_TYPE_UTILITY].atom) {
|
|
|
|
win->floating = 1;
|
|
|
|
win->quirks = SWM_Q_FLOAT | SWM_Q_ANYWHERE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (type == ewmh[_NET_WM_WINDOW_TYPE_SPLASH].atom ||
|
|
|
|
type == ewmh[_NET_WM_WINDOW_TYPE_DIALOG].atom) {
|
|
|
|
win->floating = 1;
|
|
|
|
win->quirks = SWM_Q_FLOAT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SWM_EWMH_ACTION_COUNT_MAX (6)
|
|
|
|
#define EWMH_F_FULLSCREEN (1<<0)
|
|
|
|
#define EWMH_F_ABOVE (1<<1)
|
|
|
|
#define EWMH_F_HIDDEN (1<<2)
|
|
|
|
#define EWMH_F_SKIP_PAGER (1<<3)
|
|
|
|
#define EWMH_F_SKIP_TASKBAR (1<<4)
|
|
|
|
#define SWM_F_MANUAL (1<<5)
|
|
|
|
|
|
|
|
int
|
|
|
|
ewmh_set_win_fullscreen(struct ws_win *win, int fs)
|
|
|
|
{
|
|
|
|
struct swm_geometry rg;
|
|
|
|
|
|
|
|
if (!win->ws->r)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (0);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (!win->floating)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (0);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "ewmh_set_win_fullscreen: window: 0x%lx, "
|
|
|
|
"fullscreen %s\n", win->id, YESNO(fs));
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
rg = win->ws->r->g;
|
|
|
|
|
|
|
|
if (fs) {
|
|
|
|
store_float_geom(win, win->ws->r);
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
win->g = rg;
|
2011-06-08 19:05:43 +00:00
|
|
|
} else {
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->g_floatvalid) {
|
|
|
|
/* refloat at last floating relative position */
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = win->g_float.x - win->rg_float.x + rg.x;
|
|
|
|
Y(win) = win->g_float.y - win->rg_float.y + rg.y;
|
|
|
|
WIDTH(win) = win->g_float.w;
|
|
|
|
HEIGHT(win) = win->g_float.h;
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 21:28:49 +01:00
|
|
|
return (1);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_update_actions(struct ws_win *win)
|
|
|
|
{
|
|
|
|
Atom actions[SWM_EWMH_ACTION_COUNT_MAX];
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
actions[n++] = ewmh[_NET_WM_ACTION_CLOSE].atom;
|
|
|
|
|
|
|
|
if (win->floating) {
|
|
|
|
actions[n++] = ewmh[_NET_WM_ACTION_MOVE].atom;
|
|
|
|
actions[n++] = ewmh[_NET_WM_ACTION_RESIZE].atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_ALLOWED_ACTIONS].atom,
|
|
|
|
XA_ATOM, 32, PropModeReplace, (unsigned char *)actions, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
|
|
|
|
#define _NET_WM_STATE_ADD 1 /* add/set property */
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_update_win_state(struct ws_win *win, long state, long action)
|
|
|
|
{
|
|
|
|
unsigned int mask = 0;
|
|
|
|
unsigned int changed = 0;
|
|
|
|
unsigned int orig_flags;
|
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == ewmh[_NET_WM_STATE_FULLSCREEN].atom)
|
|
|
|
mask = EWMH_F_FULLSCREEN;
|
|
|
|
if (state == ewmh[_NET_WM_STATE_ABOVE].atom)
|
|
|
|
mask = EWMH_F_ABOVE;
|
|
|
|
if (state == ewmh[_SWM_WM_STATE_MANUAL].atom)
|
|
|
|
mask = SWM_F_MANUAL;
|
|
|
|
if (state == ewmh[_NET_WM_STATE_SKIP_PAGER].atom)
|
|
|
|
mask = EWMH_F_SKIP_PAGER;
|
|
|
|
if (state == ewmh[_NET_WM_STATE_SKIP_TASKBAR].atom)
|
|
|
|
mask = EWMH_F_SKIP_TASKBAR;
|
|
|
|
|
|
|
|
|
|
|
|
orig_flags = win->ewmh_flags;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case _NET_WM_STATE_REMOVE:
|
|
|
|
win->ewmh_flags &= ~mask;
|
|
|
|
break;
|
|
|
|
case _NET_WM_STATE_ADD:
|
|
|
|
win->ewmh_flags |= mask;
|
|
|
|
break;
|
|
|
|
case _NET_WM_STATE_TOGGLE:
|
|
|
|
win->ewmh_flags ^= mask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = (win->ewmh_flags & mask) ^ (orig_flags & mask) ? 1 : 0;
|
|
|
|
|
|
|
|
if (state == ewmh[_NET_WM_STATE_ABOVE].atom)
|
|
|
|
if (changed)
|
|
|
|
if (!floating_toggle_win(win))
|
|
|
|
win->ewmh_flags = orig_flags; /* revert */
|
|
|
|
if (state == ewmh[_SWM_WM_STATE_MANUAL].atom)
|
|
|
|
if (changed)
|
|
|
|
win->manual = (win->ewmh_flags & SWM_F_MANUAL) != 0;
|
|
|
|
if (state == ewmh[_NET_WM_STATE_FULLSCREEN].atom)
|
|
|
|
if (changed)
|
2011-06-14 22:20:55 +00:00
|
|
|
if (!ewmh_set_win_fullscreen(win,
|
|
|
|
win->ewmh_flags & EWMH_F_FULLSCREEN))
|
2010-09-16 02:26:45 +00:00
|
|
|
win->ewmh_flags = orig_flags; /* revert */
|
|
|
|
|
|
|
|
XDeleteProperty(display, win->id, ewmh[_NET_WM_STATE].atom);
|
|
|
|
|
|
|
|
if (win->ewmh_flags & EWMH_F_FULLSCREEN)
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom,
|
|
|
|
XA_ATOM, 32, PropModeAppend,
|
|
|
|
(unsigned char *)&ewmh[_NET_WM_STATE_FULLSCREEN].atom, 1);
|
|
|
|
if (win->ewmh_flags & EWMH_F_SKIP_PAGER)
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom,
|
|
|
|
XA_ATOM, 32, PropModeAppend,
|
|
|
|
(unsigned char *)&ewmh[_NET_WM_STATE_SKIP_PAGER].atom, 1);
|
|
|
|
if (win->ewmh_flags & EWMH_F_SKIP_TASKBAR)
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom,
|
|
|
|
XA_ATOM, 32, PropModeAppend,
|
|
|
|
(unsigned char *)&ewmh[_NET_WM_STATE_SKIP_TASKBAR].atom, 1);
|
|
|
|
if (win->ewmh_flags & EWMH_F_ABOVE)
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom,
|
|
|
|
XA_ATOM, 32, PropModeAppend,
|
|
|
|
(unsigned char *)&ewmh[_NET_WM_STATE_ABOVE].atom, 1);
|
|
|
|
if (win->ewmh_flags & SWM_F_MANUAL)
|
|
|
|
XChangeProperty(display, win->id, ewmh[_NET_WM_STATE].atom,
|
|
|
|
XA_ATOM, 32, PropModeAppend,
|
|
|
|
(unsigned char *)&ewmh[_SWM_WM_STATE_MANUAL].atom, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_get_win_state(struct ws_win *win)
|
|
|
|
{
|
|
|
|
int success, i;
|
|
|
|
unsigned long n;
|
|
|
|
Atom *states;
|
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
win->ewmh_flags = 0;
|
|
|
|
if (win->floating)
|
|
|
|
win->ewmh_flags |= EWMH_F_ABOVE;
|
|
|
|
if (win->manual)
|
|
|
|
win->ewmh_flags |= SWM_F_MANUAL;
|
|
|
|
|
2011-06-14 22:20:55 +00:00
|
|
|
success = get_property(win->id, ewmh[_NET_WM_STATE].atom,
|
2012-02-04 14:41:30 +00:00
|
|
|
(~0L), XA_ATOM, &n, NULL, (void *)&states);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
ewmh_update_win_state(win, states[i], _NET_WM_STATE_ADD);
|
|
|
|
|
|
|
|
XFree(states);
|
|
|
|
}
|
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
/* events */
|
2009-09-25 19:25:29 +00:00
|
|
|
#ifdef SWM_DEBUG
|
2012-01-29 01:29:31 +08:00
|
|
|
char *
|
|
|
|
geteventname(XEvent *e)
|
2009-09-25 19:25:29 +00:00
|
|
|
{
|
|
|
|
char *name = NULL;
|
|
|
|
|
|
|
|
switch (e->type) {
|
|
|
|
case KeyPress:
|
|
|
|
name = "KeyPress";
|
|
|
|
break;
|
|
|
|
case KeyRelease:
|
|
|
|
name = "KeyRelease";
|
|
|
|
break;
|
|
|
|
case ButtonPress:
|
|
|
|
name = "ButtonPress";
|
|
|
|
break;
|
|
|
|
case ButtonRelease:
|
|
|
|
name = "ButtonRelease";
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
name = "MotionNotify";
|
|
|
|
break;
|
|
|
|
case EnterNotify:
|
|
|
|
name = "EnterNotify";
|
|
|
|
break;
|
|
|
|
case LeaveNotify:
|
|
|
|
name = "LeaveNotify";
|
|
|
|
break;
|
|
|
|
case FocusIn:
|
|
|
|
name = "FocusIn";
|
|
|
|
break;
|
|
|
|
case FocusOut:
|
|
|
|
name = "FocusOut";
|
|
|
|
break;
|
|
|
|
case KeymapNotify:
|
|
|
|
name = "KeymapNotify";
|
|
|
|
break;
|
|
|
|
case Expose:
|
|
|
|
name = "Expose";
|
|
|
|
break;
|
|
|
|
case GraphicsExpose:
|
|
|
|
name = "GraphicsExpose";
|
|
|
|
break;
|
|
|
|
case NoExpose:
|
|
|
|
name = "NoExpose";
|
|
|
|
break;
|
|
|
|
case VisibilityNotify:
|
|
|
|
name = "VisibilityNotify";
|
|
|
|
break;
|
|
|
|
case CreateNotify:
|
|
|
|
name = "CreateNotify";
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
|
|
|
name = "DestroyNotify";
|
|
|
|
break;
|
|
|
|
case UnmapNotify:
|
|
|
|
name = "UnmapNotify";
|
|
|
|
break;
|
|
|
|
case MapNotify:
|
|
|
|
name = "MapNotify";
|
|
|
|
break;
|
|
|
|
case MapRequest:
|
|
|
|
name = "MapRequest";
|
|
|
|
break;
|
|
|
|
case ReparentNotify:
|
|
|
|
name = "ReparentNotify";
|
|
|
|
break;
|
|
|
|
case ConfigureNotify:
|
|
|
|
name = "ConfigureNotify";
|
|
|
|
break;
|
|
|
|
case ConfigureRequest:
|
|
|
|
name = "ConfigureRequest";
|
|
|
|
break;
|
|
|
|
case GravityNotify:
|
|
|
|
name = "GravityNotify";
|
|
|
|
break;
|
|
|
|
case ResizeRequest:
|
|
|
|
name = "ResizeRequest";
|
|
|
|
break;
|
|
|
|
case CirculateNotify:
|
|
|
|
name = "CirculateNotify";
|
|
|
|
break;
|
|
|
|
case CirculateRequest:
|
|
|
|
name = "CirculateRequest";
|
|
|
|
break;
|
|
|
|
case PropertyNotify:
|
|
|
|
name = "PropertyNotify";
|
|
|
|
break;
|
|
|
|
case SelectionClear:
|
|
|
|
name = "SelectionClear";
|
|
|
|
break;
|
|
|
|
case SelectionRequest:
|
|
|
|
name = "SelectionRequest";
|
|
|
|
break;
|
|
|
|
case SelectionNotify:
|
|
|
|
name = "SelectionNotify";
|
|
|
|
break;
|
|
|
|
case ColormapNotify:
|
|
|
|
name = "ColormapNotify";
|
|
|
|
break;
|
|
|
|
case ClientMessage:
|
|
|
|
name = "ClientMessage";
|
|
|
|
break;
|
|
|
|
case MappingNotify:
|
|
|
|
name = "MappingNotify";
|
|
|
|
break;
|
2012-01-29 01:29:31 +08:00
|
|
|
default:
|
|
|
|
name = "Unknown";
|
2009-09-25 19:25:29 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 21:28:49 +01:00
|
|
|
return (name);
|
2012-01-29 01:29:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
xrandr_geteventname(XEvent *e)
|
|
|
|
{
|
2012-02-03 08:01:09 -06:00
|
|
|
char *name = NULL;
|
2012-01-29 01:29:31 +08:00
|
|
|
|
|
|
|
switch(e->type - xrandr_eventbase) {
|
|
|
|
case RRScreenChangeNotify:
|
|
|
|
name = "RRScreenChangeNotify";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
name = "Unknown";
|
|
|
|
}
|
|
|
|
|
2012-05-12 21:28:49 +01:00
|
|
|
return (name);
|
2009-09-25 19:25:29 +00:00
|
|
|
}
|
2009-10-13 02:28:47 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
dumpwins(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
unsigned int state;
|
|
|
|
XWindowAttributes wa;
|
|
|
|
|
|
|
|
if (r->ws == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("dumpwins: invalid workspace");
|
2009-10-13 02:28:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("=== managed window list ws %02d ===", r->ws->idx);
|
2009-10-13 02:28:47 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(win, &r->ws->winlist, entry) {
|
|
|
|
state = getstate(win->id);
|
|
|
|
if (!XGetWindowAttributes(display, win->id, &wa))
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("window: 0x%lx, failed XGetWindowAttributes",
|
|
|
|
win->id);
|
|
|
|
warnx("window: 0x%lx, map_state: %d, state: %d, "
|
|
|
|
"transient: 0x%lx", win->id, wa.map_state, state,
|
|
|
|
win->transient);
|
2009-10-13 02:28:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("===== unmanaged window list =====");
|
2009-10-13 02:28:47 +00:00
|
|
|
TAILQ_FOREACH(win, &r->ws->unmanagedlist, entry) {
|
|
|
|
state = getstate(win->id);
|
|
|
|
if (!XGetWindowAttributes(display, win->id, &wa))
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("window: 0x%lx, failed XGetWindowAttributes",
|
|
|
|
win->id);
|
|
|
|
warnx("window: 0x%lx, map_state: %d, state: %d, "
|
|
|
|
"transient: 0x%lx", win->id, wa.map_state, state,
|
|
|
|
win->transient);
|
2009-10-13 02:28:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("=================================");
|
2009-10-13 02:28:47 +00:00
|
|
|
}
|
2009-09-25 19:25:29 +00:00
|
|
|
#else
|
2009-10-13 02:28:47 +00:00
|
|
|
void
|
|
|
|
dumpwins(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
}
|
2009-09-25 19:25:29 +00:00
|
|
|
#endif /* SWM_DEBUG */
|
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
void expose(XEvent *);
|
|
|
|
void keypress(XEvent *);
|
|
|
|
void buttonpress(XEvent *);
|
|
|
|
void configurerequest(XEvent *);
|
|
|
|
void configurenotify(XEvent *);
|
|
|
|
void destroynotify(XEvent *);
|
|
|
|
void enternotify(XEvent *);
|
2009-10-29 11:16:33 +00:00
|
|
|
void focusevent(XEvent *);
|
2009-10-01 21:08:22 +00:00
|
|
|
void mapnotify(XEvent *);
|
2009-10-04 04:30:41 +00:00
|
|
|
void mappingnotify(XEvent *);
|
2009-01-29 21:38:49 +00:00
|
|
|
void maprequest(XEvent *);
|
|
|
|
void propertynotify(XEvent *);
|
|
|
|
void unmapnotify(XEvent *);
|
|
|
|
void visibilitynotify(XEvent *);
|
2010-09-16 02:26:45 +00:00
|
|
|
void clientmessage(XEvent *);
|
2009-01-29 21:38:49 +00:00
|
|
|
|
|
|
|
void (*handler[LASTEvent])(XEvent *) = {
|
|
|
|
[Expose] = expose,
|
|
|
|
[KeyPress] = keypress,
|
|
|
|
[ButtonPress] = buttonpress,
|
|
|
|
[ConfigureRequest] = configurerequest,
|
|
|
|
[ConfigureNotify] = configurenotify,
|
|
|
|
[DestroyNotify] = destroynotify,
|
|
|
|
[EnterNotify] = enternotify,
|
2009-10-29 11:16:33 +00:00
|
|
|
[FocusIn] = focusevent,
|
|
|
|
[FocusOut] = focusevent,
|
2009-10-01 21:08:22 +00:00
|
|
|
[MapNotify] = mapnotify,
|
2009-10-04 04:30:41 +00:00
|
|
|
[MappingNotify] = mappingnotify,
|
2009-01-29 21:38:49 +00:00
|
|
|
[MapRequest] = maprequest,
|
|
|
|
[PropertyNotify] = propertynotify,
|
|
|
|
[UnmapNotify] = unmapnotify,
|
|
|
|
[VisibilityNotify] = visibilitynotify,
|
2010-09-16 02:26:45 +00:00
|
|
|
[ClientMessage] = clientmessage,
|
2009-01-29 21:38:49 +00:00
|
|
|
};
|
|
|
|
|
2009-09-29 14:25:40 +00:00
|
|
|
void
|
|
|
|
sighdlr(int sig)
|
|
|
|
{
|
2010-07-05 21:55:38 +00:00
|
|
|
int saved_errno, status;
|
2009-09-29 14:25:40 +00:00
|
|
|
pid_t pid;
|
|
|
|
|
2010-07-05 21:55:38 +00:00
|
|
|
saved_errno = errno;
|
|
|
|
|
2009-09-29 14:25:40 +00:00
|
|
|
switch (sig) {
|
|
|
|
case SIGCHLD:
|
2010-07-05 21:55:38 +00:00
|
|
|
while ((pid = waitpid(WAIT_ANY, &status, WNOHANG)) != 0) {
|
|
|
|
if (pid == -1) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
#ifdef SWM_DEBUG
|
|
|
|
if (errno != ECHILD)
|
|
|
|
warn("sighdlr: waitpid");
|
|
|
|
#endif /* SWM_DEBUG */
|
2009-09-29 14:25:40 +00:00
|
|
|
break;
|
2010-07-05 21:55:38 +00:00
|
|
|
}
|
2011-06-06 19:52:03 +00:00
|
|
|
if (pid == searchpid)
|
|
|
|
search_resp = 1;
|
2010-07-05 21:55:38 +00:00
|
|
|
|
|
|
|
#ifdef SWM_DEBUG
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
if (WEXITSTATUS(status) != 0)
|
|
|
|
warnx("sighdlr: child exit status: %d",
|
|
|
|
WEXITSTATUS(status));
|
|
|
|
} else
|
|
|
|
warnx("sighdlr: child is terminated "
|
|
|
|
"abnormally");
|
|
|
|
#endif /* SWM_DEBUG */
|
2009-09-29 14:25:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-07-05 21:55:38 +00:00
|
|
|
|
2010-07-03 22:41:34 +00:00
|
|
|
case SIGHUP:
|
|
|
|
restart_wm = 1;
|
|
|
|
break;
|
2009-09-29 14:25:40 +00:00
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
case SIGQUIT:
|
|
|
|
running = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-05 21:55:38 +00:00
|
|
|
errno = saved_errno;
|
2009-09-29 14:25:40 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
struct pid_e *
|
|
|
|
find_pid(long pid)
|
|
|
|
{
|
|
|
|
struct pid_e *p = NULL;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "find_pid: %lu\n", pid);
|
|
|
|
|
2011-06-23 11:37:16 +00:00
|
|
|
if (pid == 0)
|
|
|
|
return (NULL);
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
TAILQ_FOREACH(p, &pidlist, entry) {
|
|
|
|
if (p->pid == pid)
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-18 23:53:03 +00:00
|
|
|
unsigned long
|
|
|
|
name_to_color(char *colorname)
|
|
|
|
{
|
|
|
|
Colormap cmap;
|
2009-01-19 05:48:11 +00:00
|
|
|
Status status;
|
2009-01-18 23:53:03 +00:00
|
|
|
XColor screen_def, exact_def;
|
|
|
|
unsigned long result = 0;
|
|
|
|
char cname[32] = "#";
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
cmap = DefaultColormap(display, screens[0].idx);
|
|
|
|
status = XAllocNamedColor(display, cmap, colorname,
|
|
|
|
&screen_def, &exact_def);
|
|
|
|
if (!status) {
|
2009-01-18 23:53:03 +00:00
|
|
|
strlcat(cname, colorname + 2, sizeof cname - 1);
|
2009-01-19 05:48:11 +00:00
|
|
|
status = XAllocNamedColor(display, cmap, cname, &screen_def,
|
2009-01-18 23:53:03 +00:00
|
|
|
&exact_def);
|
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
if (status)
|
2009-01-18 23:53:03 +00:00
|
|
|
result = screen_def.pixel;
|
|
|
|
else
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("color '%s' not found", colorname);
|
2009-01-18 23:53:03 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2009-01-22 06:21:23 +00:00
|
|
|
void
|
|
|
|
setscreencolor(char *val, int i, int c)
|
|
|
|
{
|
|
|
|
if (i > 0 && i <= ScreenCount(display)) {
|
|
|
|
screens[i - 1].c[c].color = name_to_color(val);
|
2009-09-12 21:32:21 +00:00
|
|
|
free(screens[i - 1].c[c].name);
|
2009-01-22 06:21:23 +00:00
|
|
|
if ((screens[i - 1].c[c].name = strdup(val)) == NULL)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "strdup");
|
2009-01-22 06:21:23 +00:00
|
|
|
} else if (i == -1) {
|
2009-09-12 21:32:21 +00:00
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
2009-01-22 06:21:23 +00:00
|
|
|
screens[i].c[c].color = name_to_color(val);
|
2009-09-12 21:32:21 +00:00
|
|
|
free(screens[i].c[c].name);
|
|
|
|
if ((screens[i].c[c].name = strdup(val)) == NULL)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "strdup");
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
2009-01-22 06:21:23 +00:00
|
|
|
} else
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "invalid screen index: %d out of bounds (maximum %d)",
|
2009-01-22 06:21:23 +00:00
|
|
|
i, ScreenCount(display));
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:28:15 +00:00
|
|
|
void
|
|
|
|
fancy_stacker(struct workspace *ws)
|
|
|
|
{
|
2011-11-17 19:55:05 -06:00
|
|
|
strlcpy(ws->stacker, "[ ]", sizeof ws->stacker);
|
2011-07-19 21:28:15 +00:00
|
|
|
if (ws->cur_layout->l_stack == vertical_stack)
|
2012-02-08 01:17:20 +08:00
|
|
|
snprintf(ws->stacker, sizeof ws->stacker,
|
|
|
|
ws->l_state.vertical_flip ? "[%d>%d]" : "[%d|%d]",
|
2011-07-19 21:28:15 +00:00
|
|
|
ws->l_state.vertical_mwin, ws->l_state.vertical_stacks);
|
|
|
|
if (ws->cur_layout->l_stack == horizontal_stack)
|
2012-02-08 01:17:20 +08:00
|
|
|
snprintf(ws->stacker, sizeof ws->stacker,
|
|
|
|
ws->l_state.horizontal_flip ? "[%dv%d]" : "[%d-%d]",
|
2011-07-19 21:28:15 +00:00
|
|
|
ws->l_state.horizontal_mwin, ws->l_state.horizontal_stacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
plain_stacker(struct workspace *ws)
|
|
|
|
{
|
2011-11-17 19:55:05 -06:00
|
|
|
strlcpy(ws->stacker, "[ ]", sizeof ws->stacker);
|
2011-07-19 21:28:15 +00:00
|
|
|
if (ws->cur_layout->l_stack == vertical_stack)
|
2012-02-08 01:17:20 +08:00
|
|
|
strlcpy(ws->stacker, ws->l_state.vertical_flip ? "[>]" : "[|]",
|
|
|
|
sizeof ws->stacker);
|
2011-07-19 21:28:15 +00:00
|
|
|
if (ws->cur_layout->l_stack == horizontal_stack)
|
2012-02-08 01:17:20 +08:00
|
|
|
strlcpy(ws->stacker, ws->l_state.horizontal_flip ? "[v]" : "[-]",
|
|
|
|
sizeof ws->stacker);
|
2011-07-19 21:28:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-01 11:59:40 +00:00
|
|
|
void
|
|
|
|
custom_region(char *val)
|
|
|
|
{
|
|
|
|
unsigned int sidx, x, y, w, h;
|
|
|
|
|
|
|
|
if (sscanf(val, "screen[%u]:%ux%u+%u+%u", &sidx, &w, &h, &x, &y) != 5)
|
|
|
|
errx(1, "invalid custom region, "
|
2011-12-07 21:53:12 -05:00
|
|
|
"should be 'screen[<n>]:<n>x<n>+<n>+<n>");
|
2009-02-01 11:59:40 +00:00
|
|
|
if (sidx < 1 || sidx > ScreenCount(display))
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "invalid screen index: %d out of bounds (maximum %d)",
|
2009-02-01 11:59:40 +00:00
|
|
|
sidx, ScreenCount(display));
|
|
|
|
sidx--;
|
|
|
|
|
|
|
|
if (w < 1 || h < 1)
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "region %ux%u+%u+%u too small", w, h, x, y);
|
2009-02-01 11:59:40 +00:00
|
|
|
|
2011-09-19 23:18:24 -05:00
|
|
|
if (x > DisplayWidth(display, sidx) ||
|
|
|
|
y > DisplayHeight(display, sidx) ||
|
2009-02-01 11:59:40 +00:00
|
|
|
w + x > DisplayWidth(display, sidx) ||
|
2010-11-12 01:35:01 +00:00
|
|
|
h + y > DisplayHeight(display, sidx)) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("ignoring region %ux%u+%u+%u - not within screen "
|
|
|
|
"boundaries (%ux%u)", w, h, x, y,
|
2009-02-01 11:59:40 +00:00
|
|
|
DisplayWidth(display, sidx), DisplayHeight(display, sidx));
|
2010-11-12 01:35:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-30 18:16:41 +00:00
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
new_region(&screens[sidx], x, y, w, h);
|
2009-02-01 11:59:40 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 17:50:16 +00:00
|
|
|
void
|
|
|
|
socket_setnonblock(int fd)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
|
|
|
|
err(1, "fcntl F_GETFL");
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
|
|
|
|
err(1, "fcntl F_SETFL");
|
|
|
|
}
|
|
|
|
|
2009-01-14 04:44:58 +00:00
|
|
|
void
|
2012-05-24 21:49:39 +01:00
|
|
|
bar_print(struct swm_region *r, const char *s)
|
2009-01-19 21:11:46 +00:00
|
|
|
{
|
2012-02-02 07:00:45 +08:00
|
|
|
int x = 0;
|
|
|
|
size_t len;
|
|
|
|
XRectangle ibox, lbox;
|
2011-11-28 22:31:11 -05:00
|
|
|
|
2009-01-20 06:16:05 +00:00
|
|
|
XClearWindow(display, r->bar_window);
|
2011-11-28 22:31:11 -05:00
|
|
|
|
|
|
|
len = strlen(s);
|
2012-02-02 07:00:45 +08:00
|
|
|
XmbTextExtents(bar_fs, s, len, &ibox, &lbox);
|
2011-11-28 22:31:11 -05:00
|
|
|
|
|
|
|
switch (bar_justify) {
|
|
|
|
case SWM_BAR_JUSTIFY_LEFT:
|
|
|
|
x = SWM_BAR_OFFSET;
|
|
|
|
break;
|
|
|
|
case SWM_BAR_JUSTIFY_CENTER:
|
2012-02-02 07:00:45 +08:00
|
|
|
x = (WIDTH(r) - lbox.width) / 2;
|
2011-11-28 22:31:11 -05:00
|
|
|
break;
|
|
|
|
case SWM_BAR_JUSTIFY_RIGHT:
|
2012-02-02 07:00:45 +08:00
|
|
|
x = WIDTH(r) - lbox.width - SWM_BAR_OFFSET;
|
2011-11-28 22:31:11 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x < SWM_BAR_OFFSET)
|
|
|
|
x = SWM_BAR_OFFSET;
|
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
DRAWSTRING(display, r->bar_window, bar_fs, r->s->bar_gc,
|
2012-02-11 09:45:09 +08:00
|
|
|
x, (bar_fs_extents->max_logical_extent.height - lbox.height) / 2 -
|
2012-02-02 07:00:45 +08:00
|
|
|
lbox.y, s, len);
|
2009-01-19 21:11:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 17:50:16 +00:00
|
|
|
void
|
|
|
|
bar_extra_stop(void)
|
|
|
|
{
|
|
|
|
if (bar_pipe[0]) {
|
|
|
|
close(bar_pipe[0]);
|
|
|
|
bzero(bar_pipe, sizeof bar_pipe);
|
|
|
|
}
|
|
|
|
if (bar_pid) {
|
|
|
|
kill(bar_pid, SIGTERM);
|
|
|
|
bar_pid = 0;
|
|
|
|
}
|
2012-02-02 07:00:45 +08:00
|
|
|
strlcpy((char *)bar_ext, "", sizeof bar_ext);
|
2009-01-22 17:50:16 +00:00
|
|
|
bar_extra = 0;
|
|
|
|
}
|
|
|
|
|
2009-09-29 14:25:40 +00:00
|
|
|
void
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_class_name(char *s, size_t sz, struct swm_region *r)
|
2009-09-29 14:25:40 +00:00
|
|
|
{
|
2012-05-13 01:33:38 +01:00
|
|
|
if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
|
2012-05-12 21:52:20 +01:00
|
|
|
return;
|
2012-05-13 01:33:38 +01:00
|
|
|
if (r->ws->focus->ch.res_class != NULL)
|
|
|
|
strlcat(s, r->ws->focus->ch.res_class, sz);
|
|
|
|
}
|
2012-05-12 21:52:20 +01:00
|
|
|
|
2012-05-13 01:33:38 +01:00
|
|
|
void
|
|
|
|
bar_title_name(char *s, size_t sz, struct swm_region *r)
|
|
|
|
{
|
|
|
|
if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
|
|
|
|
return;
|
|
|
|
if (r->ws->focus->ch.res_name != NULL)
|
|
|
|
strlcat(s, r->ws->focus->ch.res_name, sz);
|
2009-09-29 14:25:40 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 22:31:31 +01:00
|
|
|
void
|
|
|
|
bar_class_title_name(char *s, size_t sz, struct swm_region *r)
|
|
|
|
{
|
|
|
|
if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bar_class_name(s, sz, r);
|
|
|
|
strlcat(s, ":", sz);
|
|
|
|
bar_title_name(s, sz, r);
|
|
|
|
}
|
|
|
|
|
2012-05-31 22:28:26 +01:00
|
|
|
void
|
|
|
|
bar_window_float(char *s, size_t sz, struct swm_region *r)
|
|
|
|
{
|
|
|
|
if (r == NULL || r ->ws == NULL || r->ws->focus == NULL)
|
|
|
|
return;
|
|
|
|
if (r->ws->focus->floating)
|
|
|
|
strlcat(s, "(f)", sz);
|
|
|
|
}
|
|
|
|
|
2011-01-18 19:43:12 +00:00
|
|
|
void
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_window_name(char *s, size_t sz, struct swm_region *r)
|
2011-01-18 19:43:12 +00:00
|
|
|
{
|
2012-02-02 07:00:45 +08:00
|
|
|
unsigned char *title;
|
2011-01-18 19:43:12 +00:00
|
|
|
|
2012-05-13 01:33:38 +01:00
|
|
|
if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
|
|
|
|
return;
|
|
|
|
if ((title = get_win_name(r->ws->focus->id)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strlcat(s, (char *)title, sz);
|
|
|
|
XFree(title);
|
2011-01-18 19:43:12 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 03:03:07 +00:00
|
|
|
int urgent[SWM_WS_MAX];
|
2011-08-06 18:21:00 +00:00
|
|
|
void
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_urgent(char *s, size_t sz)
|
2011-08-06 18:21:00 +00:00
|
|
|
{
|
|
|
|
XWMHints *wmh = NULL;
|
|
|
|
struct ws_win *win;
|
2011-08-10 03:03:07 +00:00
|
|
|
int i, j;
|
|
|
|
char b[8];
|
2011-08-06 18:21:00 +00:00
|
|
|
|
2012-04-08 01:59:41 +08:00
|
|
|
for (i = 0; i < workspace_limit; i++)
|
2011-08-10 03:03:07 +00:00
|
|
|
urgent[i] = 0;
|
|
|
|
|
2011-08-06 18:21:00 +00:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2011-08-06 18:21:00 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) {
|
|
|
|
wmh = XGetWMHints(display, win->id);
|
|
|
|
if (wmh == NULL)
|
|
|
|
continue;
|
|
|
|
|
2011-08-10 03:03:07 +00:00
|
|
|
if (wmh->flags & XUrgencyHint)
|
|
|
|
urgent[j] = 1;
|
2011-08-06 18:21:00 +00:00
|
|
|
XFree(wmh);
|
|
|
|
}
|
|
|
|
|
2012-04-08 01:59:41 +08:00
|
|
|
for (i = 0; i < workspace_limit; i++) {
|
2011-08-10 03:03:07 +00:00
|
|
|
if (urgent[i])
|
|
|
|
snprintf(b, sizeof b, "%d ", i + 1);
|
|
|
|
else
|
|
|
|
snprintf(b, sizeof b, "- ");
|
|
|
|
strlcat(s, b, sz);
|
|
|
|
}
|
2011-08-06 18:21:00 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 21:11:46 +00:00
|
|
|
void
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_workspace_name(char *s, size_t sz, struct swm_region *r)
|
2009-01-14 04:44:58 +00:00
|
|
|
{
|
2012-05-13 01:33:38 +01:00
|
|
|
if (r == NULL || r->ws == NULL)
|
|
|
|
return;
|
|
|
|
if (r->ws->name != NULL)
|
|
|
|
strlcat(s, r->ws->name, sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build the default bar format according to the defined enabled options */
|
|
|
|
void
|
2012-05-24 21:49:39 +01:00
|
|
|
bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t sz)
|
2012-05-13 01:33:38 +01:00
|
|
|
{
|
|
|
|
/* if format provided, just copy the buffers */
|
|
|
|
if (bar_format != NULL) {
|
|
|
|
strlcpy(fmtnew, fmtexp, sz);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the output buffer */
|
|
|
|
*fmtnew = '\0';
|
|
|
|
|
|
|
|
strlcat(fmtnew, "+N:+I ", sz);
|
|
|
|
if (stack_enabled)
|
|
|
|
strlcat(fmtnew, "+S", sz);
|
|
|
|
strlcat(fmtnew, " ", sz);
|
|
|
|
|
|
|
|
/* only show the workspace name if there's actually one */
|
|
|
|
if (r != NULL && r->ws != NULL && r->ws->name != NULL)
|
|
|
|
strlcat(fmtnew, "<+D>", sz);
|
|
|
|
strlcat(fmtnew, " ", sz);
|
|
|
|
|
|
|
|
if (clock_enabled) {
|
|
|
|
strlcat(fmtnew, fmtexp, sz);
|
|
|
|
strlcat(fmtnew, " ", sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bar_urgent already adds the space before the last asterisk */
|
|
|
|
if (urgent_enabled)
|
|
|
|
strlcat(fmtnew, "* +U* ", sz);
|
|
|
|
|
2012-05-31 22:21:59 +01:00
|
|
|
if (title_class_enabled) {
|
2012-05-13 01:33:38 +01:00
|
|
|
strlcat(fmtnew, "+C", sz);
|
2012-05-31 22:21:59 +01:00
|
|
|
if (title_name_enabled == 0)
|
|
|
|
strlcat(fmtnew, " ", sz);
|
|
|
|
}
|
|
|
|
|
2012-05-31 22:28:26 +01:00
|
|
|
/* checks needed by the colon and floating strlcat(3) calls below */
|
|
|
|
if (r != NULL && r->ws != NULL && r->ws->focus != NULL) {
|
|
|
|
if (title_name_enabled) {
|
|
|
|
if (title_class_enabled)
|
|
|
|
strlcat(fmtnew, ":", sz);
|
|
|
|
strlcat(fmtnew, "+T ", sz);
|
|
|
|
}
|
|
|
|
if (window_name_enabled) {
|
|
|
|
if (r->ws->focus->floating)
|
|
|
|
strlcat(fmtnew, "+F ", sz);
|
|
|
|
strlcat(fmtnew, "+64W ", sz);
|
|
|
|
}
|
2012-05-13 01:33:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* finally add the action script output and the version */
|
2012-05-18 15:04:21 +01:00
|
|
|
strlcat(fmtnew, " +A +V", sz);
|
2012-05-13 01:33:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* replaces the bar format character sequences (like in tmux(1)) */
|
2012-05-13 23:15:11 +01:00
|
|
|
char *
|
|
|
|
bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep,
|
|
|
|
size_t sz)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
char num[8], tmp[SWM_BAR_MAX];
|
|
|
|
int limit;
|
|
|
|
size_t len, numoff = 0;
|
|
|
|
|
|
|
|
/* reset strlcat(3) buffer */
|
|
|
|
*tmp = '\0';
|
|
|
|
|
|
|
|
/* get number, if any */
|
|
|
|
fmt++;
|
|
|
|
while (*fmt != '\0' && isdigit((unsigned char) *fmt)) {
|
|
|
|
if (numoff >= sizeof num - 1)
|
|
|
|
break;
|
|
|
|
num[numoff++] = *fmt++;
|
|
|
|
}
|
|
|
|
num[numoff] = '\0';
|
|
|
|
|
|
|
|
if ((limit = strtonum(num, 1, sizeof tmp - 1, NULL)) == 0)
|
|
|
|
limit = sizeof tmp - 1;
|
|
|
|
|
|
|
|
/* if number is too big, skip to the first non-digit */
|
|
|
|
if (numoff >= sizeof num - 1) {
|
|
|
|
while (*fmt != '\0' && isdigit((unsigned char) *fmt))
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
/* there is nothing to replace (ie EOL) */
|
|
|
|
if (*fmt == '\0')
|
|
|
|
return (fmt);
|
|
|
|
|
|
|
|
switch (*fmt) {
|
|
|
|
case 'A':
|
|
|
|
snprintf(tmp, sizeof tmp, "%s", bar_ext);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
bar_class_name(tmp, sizeof tmp, r);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
bar_workspace_name(tmp, sizeof tmp, r);
|
|
|
|
break;
|
2012-05-31 22:28:26 +01:00
|
|
|
case 'F':
|
|
|
|
bar_window_float(tmp, sizeof tmp, r);
|
|
|
|
break;
|
2012-05-13 23:15:11 +01:00
|
|
|
case 'I':
|
|
|
|
snprintf(tmp, sizeof tmp, "%d", r->ws->idx + 1);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
snprintf(tmp, sizeof tmp, "%d", r->s->idx + 1);
|
|
|
|
break;
|
2012-05-31 22:31:31 +01:00
|
|
|
case 'P':
|
|
|
|
bar_class_title_name(tmp, sizeof tmp, r);
|
|
|
|
break;
|
2012-05-13 23:15:11 +01:00
|
|
|
case 'S':
|
|
|
|
snprintf(tmp, sizeof tmp, "%s", r->ws->stacker);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
bar_title_name(tmp, sizeof tmp, r);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
bar_urgent(tmp, sizeof tmp);
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
snprintf(tmp, sizeof tmp, "%s", bar_vertext);
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
bar_window_name(tmp, sizeof tmp, r);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown character sequence; copy as-is */
|
|
|
|
snprintf(tmp, sizeof tmp, "+%c", *fmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(tmp);
|
|
|
|
ptr = tmp;
|
|
|
|
if (len < limit)
|
|
|
|
limit = len;
|
|
|
|
while (limit-- > 0) {
|
|
|
|
if (*offrep >= sz - 1)
|
|
|
|
break;
|
|
|
|
fmtrep[(*offrep)++] = *ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt++;
|
|
|
|
return (fmt);
|
|
|
|
}
|
|
|
|
|
2012-05-13 01:33:38 +01:00
|
|
|
void
|
2012-05-13 19:00:16 +01:00
|
|
|
bar_replace(char *fmt, char *fmtrep, struct swm_region *r, size_t sz)
|
2012-05-13 01:33:38 +01:00
|
|
|
{
|
|
|
|
size_t off;
|
|
|
|
|
|
|
|
off = 0;
|
2012-05-13 23:15:11 +01:00
|
|
|
while (*fmt != '\0') {
|
|
|
|
if (*fmt != '+') {
|
2012-05-13 01:33:38 +01:00
|
|
|
/* skip ordinary characters */
|
|
|
|
if (off >= sz - 1)
|
|
|
|
break;
|
2012-05-13 23:15:11 +01:00
|
|
|
fmtrep[off++] = *fmt++;
|
2012-05-13 01:33:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* character sequence found; replace it */
|
2012-05-13 23:15:11 +01:00
|
|
|
fmt = bar_replace_seq(fmt, fmtrep, r, &off, sz);
|
|
|
|
if (off >= sz - 1)
|
2012-05-13 01:33:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmtrep[off] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bar_fmt_expand(char *fmtexp, size_t sz)
|
|
|
|
{
|
|
|
|
char *fmt = NULL;
|
|
|
|
size_t len;
|
2009-01-14 04:44:58 +00:00
|
|
|
struct tm tm;
|
2012-05-13 01:33:38 +01:00
|
|
|
time_t tmt;
|
|
|
|
|
|
|
|
/* start by grabbing the current time and date */
|
|
|
|
time(&tmt);
|
|
|
|
localtime_r(&tmt, &tm);
|
|
|
|
|
|
|
|
/* figure out what to expand */
|
|
|
|
if (bar_format != NULL)
|
|
|
|
fmt = bar_format;
|
|
|
|
else if (bar_format == NULL && clock_enabled)
|
|
|
|
fmt = clock_format;
|
|
|
|
/* if nothing to expand bail out */
|
|
|
|
if (fmt == NULL) {
|
|
|
|
*fmtexp = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy as-is, just in case the format shouldn't be expanded below */
|
|
|
|
strlcpy(fmtexp, fmt, sz);
|
|
|
|
/* finally pass the string through strftime(3) */
|
|
|
|
#ifndef SWM_DENY_CLOCK_FORMAT
|
2012-05-13 22:52:23 +01:00
|
|
|
if ((len = strftime(fmtexp, sz, fmt, &tm)) == 0)
|
|
|
|
warnx("format too long");
|
2012-05-13 01:33:38 +01:00
|
|
|
fmtexp[len] = '\0';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bar_fmt_print(void)
|
|
|
|
{
|
|
|
|
char fmtexp[SWM_BAR_MAX], fmtnew[SWM_BAR_MAX];
|
|
|
|
char fmtrep[SWM_BAR_MAX];
|
|
|
|
int i;
|
2009-01-19 21:11:46 +00:00
|
|
|
struct swm_region *r;
|
2012-05-13 01:33:38 +01:00
|
|
|
|
|
|
|
/* expand the format by first passing it through strftime(3) */
|
|
|
|
bar_fmt_expand(fmtexp, sizeof fmtexp);
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry) {
|
|
|
|
bar_fmt(fmtexp, fmtnew, r, sizeof fmtnew);
|
2012-05-13 19:00:16 +01:00
|
|
|
bar_replace(fmtnew, fmtrep, r, sizeof fmtrep);
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_print(r, fmtrep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bar_update(void)
|
|
|
|
{
|
2009-01-22 17:50:16 +00:00
|
|
|
size_t len;
|
2012-05-13 01:33:38 +01:00
|
|
|
char *b;
|
2009-01-22 17:50:16 +00:00
|
|
|
|
2009-01-14 07:00:38 +00:00
|
|
|
if (bar_enabled == 0)
|
|
|
|
return;
|
2009-01-22 17:50:16 +00:00
|
|
|
if (bar_extra && bar_extra_running) {
|
|
|
|
/* ignore short reads; it'll correct itself */
|
|
|
|
while ((b = fgetln(stdin, &len)) != NULL)
|
|
|
|
if (b && b[len - 1] == '\n') {
|
|
|
|
b[len - 1] = '\0';
|
2012-02-02 07:00:45 +08:00
|
|
|
strlcpy((char *)bar_ext, b, sizeof bar_ext);
|
2009-01-22 17:50:16 +00:00
|
|
|
}
|
|
|
|
if (b == NULL && errno != EAGAIN) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("bar_update: bar_extra failed");
|
2009-01-22 17:50:16 +00:00
|
|
|
bar_extra_stop();
|
|
|
|
}
|
|
|
|
} else
|
2012-02-02 07:00:45 +08:00
|
|
|
strlcpy((char *)bar_ext, "", sizeof bar_ext);
|
2009-01-22 17:50:16 +00:00
|
|
|
|
2012-05-13 01:33:38 +01:00
|
|
|
bar_fmt_print();
|
2009-01-23 22:50:38 +00:00
|
|
|
alarm(bar_delay);
|
2009-01-14 06:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bar_signal(int sig)
|
|
|
|
{
|
2009-01-19 19:27:36 +00:00
|
|
|
bar_alarm = 1;
|
2009-01-14 04:44:58 +00:00
|
|
|
}
|
2009-01-14 06:08:16 +00:00
|
|
|
|
2009-01-14 07:00:38 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
bar_toggle(struct swm_region *r, union arg *args)
|
2009-01-14 07:00:38 +00:00
|
|
|
{
|
2009-01-19 19:27:36 +00:00
|
|
|
struct swm_region *tmpr;
|
2009-10-12 04:09:17 +00:00
|
|
|
int i, sc = ScreenCount(display);
|
2009-01-14 07:24:05 +00:00
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
DNPRINTF(SWM_D_BAR, "bar_toggle\n");
|
2009-01-14 07:00:38 +00:00
|
|
|
|
2009-02-12 21:14:14 +00:00
|
|
|
if (bar_enabled)
|
2009-01-20 06:16:05 +00:00
|
|
|
for (i = 0; i < sc; i++)
|
2009-01-19 09:05:02 +00:00
|
|
|
TAILQ_FOREACH(tmpr, &screens[i].rl, entry)
|
|
|
|
XUnmapWindow(display, tmpr->bar_window);
|
2009-02-12 21:14:14 +00:00
|
|
|
else
|
2009-01-20 06:16:05 +00:00
|
|
|
for (i = 0; i < sc; i++)
|
2009-01-19 09:05:02 +00:00
|
|
|
TAILQ_FOREACH(tmpr, &screens[i].rl, entry)
|
|
|
|
XMapRaised(display, tmpr->bar_window);
|
2009-02-12 21:14:14 +00:00
|
|
|
|
2009-01-19 03:30:39 +00:00
|
|
|
bar_enabled = !bar_enabled;
|
2009-01-14 07:00:38 +00:00
|
|
|
|
|
|
|
stack();
|
2009-01-19 05:48:11 +00:00
|
|
|
/* must be after stack */
|
2009-02-10 04:40:29 +00:00
|
|
|
bar_update();
|
2009-01-14 07:00:38 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 17:50:16 +00:00
|
|
|
void
|
|
|
|
bar_refresh(void)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
|
|
|
struct swm_region *r;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* do this here because the conf file is in memory */
|
|
|
|
if (bar_extra && bar_extra_running == 0 && bar_argv[0]) {
|
|
|
|
/* launch external status app */
|
|
|
|
bar_extra_running = 1;
|
|
|
|
if (pipe(bar_pipe) == -1)
|
|
|
|
err(1, "pipe error");
|
|
|
|
socket_setnonblock(bar_pipe[0]);
|
|
|
|
socket_setnonblock(bar_pipe[1]); /* XXX hmmm, really? */
|
|
|
|
if (dup2(bar_pipe[0], 0) == -1)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "dup2");
|
2009-01-22 17:50:16 +00:00
|
|
|
if (dup2(bar_pipe[1], 1) == -1)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "dup2");
|
2009-01-22 17:50:16 +00:00
|
|
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
|
|
|
err(1, "could not disable SIGPIPE");
|
|
|
|
switch (bar_pid = fork()) {
|
|
|
|
case -1:
|
|
|
|
err(1, "cannot fork");
|
|
|
|
break;
|
|
|
|
case 0: /* child */
|
|
|
|
close(bar_pipe[0]);
|
|
|
|
execvp(bar_argv[0], bar_argv);
|
|
|
|
err(1, "%s external app failed", bar_argv[0]);
|
|
|
|
break;
|
|
|
|
default: /* parent */
|
|
|
|
close(bar_pipe[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(&wa, sizeof wa);
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry) {
|
|
|
|
wa.border_pixel =
|
|
|
|
screens[i].c[SWM_S_COLOR_BAR_BORDER].color;
|
|
|
|
wa.background_pixel =
|
|
|
|
screens[i].c[SWM_S_COLOR_BAR].color;
|
|
|
|
XChangeWindowAttributes(display, r->bar_window,
|
|
|
|
CWBackPixel | CWBorderPixel, &wa);
|
|
|
|
}
|
|
|
|
bar_update();
|
|
|
|
}
|
|
|
|
|
2009-01-14 17:10:52 +00:00
|
|
|
void
|
2009-01-19 05:48:11 +00:00
|
|
|
bar_setup(struct swm_region *r)
|
2009-01-14 17:10:52 +00:00
|
|
|
{
|
2012-02-02 07:00:45 +08:00
|
|
|
char *default_string;
|
|
|
|
char **missing_charsets;
|
|
|
|
int num_missing_charsets = 0;
|
2010-07-15 14:03:04 +00:00
|
|
|
int i, x, y;
|
2009-01-14 17:10:52 +00:00
|
|
|
|
2010-07-07 12:52:42 +00:00
|
|
|
if (bar_fs) {
|
2012-02-02 07:00:45 +08:00
|
|
|
XFreeFontSet(display, bar_fs);
|
2010-07-07 12:52:42 +00:00
|
|
|
bar_fs = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_BAR, "bar_setup: loading bar_fonts: %s\n", bar_fonts);
|
|
|
|
|
|
|
|
bar_fs = XCreateFontSet(display, bar_fonts, &missing_charsets,
|
|
|
|
&num_missing_charsets, &default_string);
|
|
|
|
|
|
|
|
if (num_missing_charsets > 0) {
|
|
|
|
warnx("Unable to load charset(s):");
|
|
|
|
|
|
|
|
for (i = 0; i < num_missing_charsets; ++i)
|
|
|
|
warnx("%s", missing_charsets[i]);
|
|
|
|
|
|
|
|
XFreeStringList(missing_charsets);
|
|
|
|
|
|
|
|
if (strcmp(default_string, ""))
|
|
|
|
warnx("Glyphs from those sets will be replaced "
|
|
|
|
"by '%s'.", default_string);
|
|
|
|
else
|
|
|
|
warnx("Glyphs from those sets won't be drawn.");
|
2009-01-14 17:10:52 +00:00
|
|
|
}
|
2012-02-02 07:00:45 +08:00
|
|
|
|
2010-07-07 12:52:42 +00:00
|
|
|
if (bar_fs == NULL)
|
2012-02-02 07:00:45 +08:00
|
|
|
errx(1, "Error creating font set structure.");
|
|
|
|
|
|
|
|
bar_fs_extents = XExtentsOfFontSet(bar_fs);
|
2010-07-07 12:52:42 +00:00
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
bar_height = bar_fs_extents->max_logical_extent.height +
|
2011-06-14 22:20:55 +00:00
|
|
|
2 * bar_border_width;
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
if (bar_height < 1)
|
|
|
|
bar_height = 1;
|
|
|
|
|
2010-07-15 14:03:04 +00:00
|
|
|
x = X(r);
|
|
|
|
y = bar_at_bottom ? (Y(r) + HEIGHT(r) - bar_height) : Y(r);
|
2009-01-14 17:10:52 +00:00
|
|
|
|
2009-08-30 18:16:41 +00:00
|
|
|
r->bar_window = XCreateSimpleWindow(display,
|
2011-06-14 22:20:55 +00:00
|
|
|
r->s->root, x, y, WIDTH(r) - 2 * bar_border_width,
|
|
|
|
bar_height - 2 * bar_border_width,
|
2011-03-11 21:34:19 +00:00
|
|
|
bar_border_width, r->s->c[SWM_S_COLOR_BAR_BORDER].color,
|
2009-01-22 06:21:23 +00:00
|
|
|
r->s->c[SWM_S_COLOR_BAR].color);
|
2009-01-19 05:48:11 +00:00
|
|
|
XSelectInput(display, r->bar_window, VisibilityChangeMask);
|
2009-01-19 03:30:39 +00:00
|
|
|
if (bar_enabled)
|
2009-01-19 05:48:11 +00:00
|
|
|
XMapRaised(display, r->bar_window);
|
2012-02-02 07:00:45 +08:00
|
|
|
DNPRINTF(SWM_D_BAR, "bar_setup: bar_window: 0x%lx\n", r->bar_window);
|
2009-01-14 17:10:52 +00:00
|
|
|
|
|
|
|
if (signal(SIGALRM, bar_signal) == SIG_ERR)
|
|
|
|
err(1, "could not install bar_signal");
|
2009-01-22 17:50:16 +00:00
|
|
|
bar_refresh();
|
2009-01-20 06:16:05 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 21:15:29 +00:00
|
|
|
void
|
|
|
|
drain_enter_notify(void)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
XEvent cne;
|
|
|
|
|
|
|
|
while (XCheckMaskEvent(display, EnterWindowMask, &cne))
|
|
|
|
i++;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "drain_enter_notify: drained: %d\n", i);
|
2011-06-09 21:15:29 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 21:08:22 +00:00
|
|
|
void
|
|
|
|
set_win_state(struct ws_win *win, long state)
|
|
|
|
{
|
|
|
|
long data[] = {state, None};
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "set_win_state: window: 0x%lx\n", win->id);
|
2009-10-01 21:08:22 +00:00
|
|
|
|
2009-10-06 17:04:53 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
2009-10-04 21:53:31 +00:00
|
|
|
|
2009-10-01 21:08:22 +00:00
|
|
|
XChangeProperty(display, win->id, astate, astate, 32, PropModeReplace,
|
|
|
|
(unsigned char *)data, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
getstate(Window w)
|
|
|
|
{
|
|
|
|
long result = -1;
|
|
|
|
unsigned char *p = NULL;
|
2010-09-16 02:26:45 +00:00
|
|
|
unsigned long n;
|
2009-10-01 21:08:22 +00:00
|
|
|
|
2012-02-04 14:41:30 +00:00
|
|
|
if (!get_property(w, astate, 2L, astate, &n, NULL, &p))
|
2009-10-01 21:08:22 +00:00
|
|
|
return (-1);
|
|
|
|
if (n != 0)
|
|
|
|
result = *((long *)p);
|
|
|
|
XFree(p);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2009-01-30 20:16:01 +00:00
|
|
|
void
|
|
|
|
version(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
bar_version = !bar_version;
|
|
|
|
if (bar_version)
|
2012-01-29 01:29:31 +08:00
|
|
|
snprintf(bar_vertext, sizeof bar_vertext,
|
2012-02-15 14:09:13 -06:00
|
|
|
"Version: %s Build: %s", SPECTRWM_VERSION, buildstr);
|
2009-01-30 20:16:01 +00:00
|
|
|
else
|
|
|
|
strlcpy(bar_vertext, "", sizeof bar_vertext);
|
|
|
|
bar_update();
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:16:10 +00:00
|
|
|
void
|
|
|
|
client_msg(struct ws_win *win, Atom a)
|
|
|
|
{
|
|
|
|
XClientMessageEvent cm;
|
|
|
|
|
2009-10-08 04:50:27 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-02-10 18:16:10 +00:00
|
|
|
bzero(&cm, sizeof cm);
|
|
|
|
cm.type = ClientMessage;
|
|
|
|
cm.window = win->id;
|
|
|
|
cm.message_type = aprot;
|
|
|
|
cm.format = 32;
|
|
|
|
cm.data.l[0] = a;
|
|
|
|
cm.data.l[1] = CurrentTime;
|
|
|
|
XSendEvent(display, win->id, False, 0L, (XEvent *)&cm);
|
|
|
|
}
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
/* synthetic response to a ConfigureRequest when not making a change */
|
2009-10-12 04:09:17 +00:00
|
|
|
void
|
2011-06-03 20:55:02 +00:00
|
|
|
config_win(struct ws_win *win, XConfigureRequestEvent *ev)
|
2009-01-16 23:40:01 +00:00
|
|
|
{
|
|
|
|
XConfigureEvent ce;
|
|
|
|
|
2009-10-08 04:50:27 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-02-02 04:50:43 +08:00
|
|
|
/* send notification of unchanged state. */
|
|
|
|
ce.type = ConfigureNotify;
|
|
|
|
ce.x = X(win);
|
|
|
|
ce.y = Y(win);
|
|
|
|
ce.width = WIDTH(win);
|
|
|
|
ce.height = HEIGHT(win);
|
|
|
|
ce.override_redirect = False;
|
2011-06-03 22:33:03 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (ev == NULL) {
|
|
|
|
/* EWMH */
|
2011-06-03 20:55:02 +00:00
|
|
|
ce.display = display;
|
|
|
|
ce.event = win->id;
|
|
|
|
ce.window = win->id;
|
|
|
|
ce.border_width = border_width;
|
|
|
|
ce.above = None;
|
|
|
|
} else {
|
2012-01-29 01:29:31 +08:00
|
|
|
/* normal */
|
2011-06-03 20:55:02 +00:00
|
|
|
ce.display = ev->display;
|
|
|
|
ce.event = ev->window;
|
|
|
|
ce.window = ev->window;
|
2012-02-04 01:58:52 +08:00
|
|
|
|
|
|
|
/* make response appear more WM_SIZE_HINTS-compliant */
|
|
|
|
if (win->sh_mask)
|
|
|
|
DNPRINTF(SWM_D_MISC, "config_win: hints: window: 0x%lx,"
|
|
|
|
" sh_mask: %ld, min: %d x %d, max: %d x %d, inc: "
|
|
|
|
"%d x %d\n", win->id, win->sh_mask, SH_MIN_W(win),
|
|
|
|
SH_MIN_H(win), SH_MAX_W(win), SH_MAX_H(win),
|
|
|
|
SH_INC_W(win), SH_INC_H(win));
|
|
|
|
|
|
|
|
/* min size */
|
|
|
|
if (SH_MIN(win)) {
|
|
|
|
/* the hint may be set... to 0! */
|
|
|
|
if (SH_MIN_W(win) > 0 && ce.width < SH_MIN_W(win))
|
|
|
|
ce.width = SH_MIN_W(win);
|
|
|
|
if (SH_MIN_H(win) > 0 && ce.height < SH_MIN_H(win))
|
|
|
|
ce.height = SH_MIN_H(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* max size */
|
|
|
|
if (SH_MAX(win)) {
|
|
|
|
/* may also be advertized as 0 */
|
|
|
|
if (SH_MAX_W(win) > 0 && ce.width > SH_MAX_W(win))
|
|
|
|
ce.width = SH_MAX_W(win);
|
|
|
|
if (SH_MAX_H(win) > 0 && ce.height > SH_MAX_H(win))
|
|
|
|
ce.height = SH_MAX_H(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* resize increment. */
|
|
|
|
if (SH_INC(win)) {
|
|
|
|
if (SH_INC_W(win) > 1 && ce.width > SH_INC_W(win))
|
|
|
|
ce.width -= (ce.width - SH_MIN_W(win)) %
|
|
|
|
SH_INC_W(win);
|
|
|
|
if (SH_INC_H(win) > 1 && ce.height > SH_INC_H(win))
|
|
|
|
ce.height -= (ce.height - SH_MIN_H(win)) %
|
|
|
|
SH_INC_H(win);
|
|
|
|
}
|
|
|
|
|
2012-02-02 04:50:43 +08:00
|
|
|
/* adjust x and y for requested border_width. */
|
|
|
|
ce.x += border_width - ev->border_width;
|
|
|
|
ce.y += border_width - ev->border_width;
|
2011-06-03 20:55:02 +00:00
|
|
|
ce.border_width = ev->border_width;
|
|
|
|
ce.above = ev->above;
|
|
|
|
}
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "config_win: ewmh: %s, window: 0x%lx, (x,y) w x h: "
|
|
|
|
"(%d,%d) %d x %d, border: %d\n", YESNO(ev == NULL), win->id, ce.x,
|
|
|
|
ce.y, ce.width, ce.height, ce.border_width);
|
|
|
|
|
2009-01-16 23:40:01 +00:00
|
|
|
XSendEvent(display, win->id, False, StructureNotifyMask, (XEvent *)&ce);
|
|
|
|
}
|
|
|
|
|
2009-01-14 22:06:48 +00:00
|
|
|
int
|
2009-01-19 05:48:11 +00:00
|
|
|
count_win(struct workspace *ws, int count_transient)
|
2009-01-14 22:06:48 +00:00
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
int count = 0;
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry) {
|
2009-01-16 23:40:01 +00:00
|
|
|
if (count_transient == 0 && win->floating)
|
|
|
|
continue;
|
2009-01-14 22:06:48 +00:00
|
|
|
if (count_transient == 0 && win->transient)
|
|
|
|
continue;
|
2011-06-06 19:52:03 +00:00
|
|
|
if (win->iconic)
|
|
|
|
continue;
|
2009-01-14 22:06:48 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
DNPRINTF(SWM_D_MISC, "count_win: %d\n", count);
|
|
|
|
|
|
|
|
return (count);
|
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
quit(struct swm_region *r, union arg *args)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2009-01-13 22:51:20 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "quit\n");
|
2009-01-13 15:55:13 +00:00
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-01 21:08:22 +00:00
|
|
|
void
|
|
|
|
unmap_window(struct ws_win *win)
|
|
|
|
{
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-04 21:53:31 +00:00
|
|
|
/* don't unmap again */
|
2009-10-13 02:28:47 +00:00
|
|
|
if (getstate(win->id) == IconicState)
|
2009-10-04 21:53:31 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-09 16:31:58 +00:00
|
|
|
set_win_state(win, IconicState);
|
2009-10-06 17:04:53 +00:00
|
|
|
|
2009-10-01 21:08:22 +00:00
|
|
|
XUnmapWindow(display, win->id);
|
2010-08-11 03:15:40 +00:00
|
|
|
XSetWindowBorder(display, win->id,
|
2010-09-16 02:26:45 +00:00
|
|
|
win->s->c[SWM_S_COLOR_UNFOCUS].color);
|
2009-10-01 21:08:22 +00:00
|
|
|
}
|
|
|
|
|
2009-01-27 19:56:47 +00:00
|
|
|
void
|
|
|
|
unmap_all(void)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2009-01-27 19:56:47 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
|
2009-10-01 21:08:22 +00:00
|
|
|
unmap_window(win);
|
2009-01-27 19:56:47 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 19:49:58 +00:00
|
|
|
void
|
|
|
|
fake_keypress(struct ws_win *win, int keysym, int modifiers)
|
|
|
|
{
|
|
|
|
XKeyEvent event;
|
|
|
|
|
2009-10-08 04:50:27 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-02-07 19:49:58 +00:00
|
|
|
event.display = display; /* Ignored, but what the hell */
|
|
|
|
event.window = win->id;
|
|
|
|
event.root = win->s->root;
|
|
|
|
event.subwindow = None;
|
|
|
|
event.time = CurrentTime;
|
2012-01-29 01:29:31 +08:00
|
|
|
event.x = X(win);
|
|
|
|
event.y = Y(win);
|
2009-02-07 19:49:58 +00:00
|
|
|
event.x_root = 1;
|
|
|
|
event.y_root = 1;
|
|
|
|
event.same_screen = True;
|
|
|
|
event.keycode = XKeysymToKeycode(display, keysym);
|
|
|
|
event.state = modifiers;
|
|
|
|
|
|
|
|
event.type = KeyPress;
|
|
|
|
XSendEvent(event.display, event.window, True,
|
|
|
|
KeyPressMask, (XEvent *)&event);
|
|
|
|
|
|
|
|
event.type = KeyRelease;
|
|
|
|
XSendEvent(event.display, event.window, True,
|
|
|
|
KeyPressMask, (XEvent *)&event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-15 02:14:08 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
restart(struct swm_region *r, union arg *args)
|
2009-01-15 17:22:05 +00:00
|
|
|
{
|
2009-01-17 17:23:52 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "restart: %s\n", start_argv[0]);
|
|
|
|
|
2009-01-19 19:27:36 +00:00
|
|
|
/* disable alarm because the following code may not be interrupted */
|
|
|
|
alarm(0);
|
|
|
|
if (signal(SIGALRM, SIG_IGN) == SIG_ERR)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "can't disable alarm");
|
2009-01-19 19:27:36 +00:00
|
|
|
|
2009-01-22 17:50:16 +00:00
|
|
|
bar_extra_stop();
|
|
|
|
bar_extra = 1;
|
2009-01-27 19:56:47 +00:00
|
|
|
unmap_all();
|
2009-01-15 02:14:08 +00:00
|
|
|
XCloseDisplay(display);
|
2009-01-17 17:23:52 +00:00
|
|
|
execvp(start_argv[0], start_argv);
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("execvp failed");
|
2009-01-19 09:05:02 +00:00
|
|
|
quit(NULL, NULL);
|
2009-01-15 02:14:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_region *
|
2009-01-19 09:05:02 +00:00
|
|
|
root_to_region(Window root)
|
2009-01-19 05:48:11 +00:00
|
|
|
{
|
2009-02-03 06:45:53 +00:00
|
|
|
struct swm_region *r = NULL;
|
2009-01-19 14:15:31 +00:00
|
|
|
Window rr, cr;
|
|
|
|
int i, x, y, wx, wy;
|
|
|
|
unsigned int mask;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-19 09:05:02 +00:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
|
|
|
if (screens[i].root == root)
|
|
|
|
break;
|
|
|
|
|
2009-08-30 18:16:41 +00:00
|
|
|
if (XQueryPointer(display, screens[i].root,
|
2009-02-03 06:45:53 +00:00
|
|
|
&rr, &cr, &x, &y, &wx, &wy, &mask) != False) {
|
|
|
|
/* choose a region based on pointer location */
|
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
2009-01-24 17:57:26 +00:00
|
|
|
if (x >= X(r) && x <= X(r) + WIDTH(r) &&
|
|
|
|
y >= Y(r) && y <= Y(r) + HEIGHT(r))
|
2009-01-22 01:22:09 +00:00
|
|
|
break;
|
2009-01-19 09:05:02 +00:00
|
|
|
}
|
2009-02-03 06:45:53 +00:00
|
|
|
|
|
|
|
if (r == NULL)
|
|
|
|
r = TAILQ_FIRST(&screens[i].rl);
|
|
|
|
|
2009-01-19 09:05:02 +00:00
|
|
|
return (r);
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 02:28:47 +00:00
|
|
|
struct ws_win *
|
|
|
|
find_unmanaged_window(Window id)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2009-10-13 02:28:47 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].unmanagedlist,
|
|
|
|
entry)
|
|
|
|
if (id == win->id)
|
|
|
|
return (win);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
struct ws_win *
|
|
|
|
find_window(Window id)
|
|
|
|
{
|
2009-01-19 14:15:31 +00:00
|
|
|
struct ws_win *win;
|
2009-11-06 04:41:28 +00:00
|
|
|
Window wrr, wpr, *wcr = NULL;
|
2010-09-16 02:26:45 +00:00
|
|
|
int i, j;
|
|
|
|
unsigned int nc;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
|
|
|
|
if (id == win->id)
|
|
|
|
return (win);
|
2009-11-06 04:41:28 +00:00
|
|
|
|
|
|
|
/* if we were looking for the parent return that window instead */
|
|
|
|
if (XQueryTree(display, id, &wrr, &wpr, &wcr, &nc) == 0)
|
|
|
|
return (NULL);
|
|
|
|
if (wcr)
|
|
|
|
XFree(wcr);
|
|
|
|
|
|
|
|
/* ignore not found and root */
|
|
|
|
if (wpr == 0 || wrr == wpr)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* look for parent */
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2009-11-06 04:41:28 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
|
|
|
|
if (wpr == win->id)
|
|
|
|
return (win);
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
2011-06-23 02:15:53 +00:00
|
|
|
spawn(int ws_idx, union arg *args, int close_fd)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2010-07-15 13:58:25 +00:00
|
|
|
int fd;
|
|
|
|
char *ret = NULL;
|
2009-01-27 06:50:57 +00:00
|
|
|
|
2009-01-13 22:51:20 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "spawn: %s\n", args->argv[0]);
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if (display)
|
|
|
|
close(ConnectionNumber(display));
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
setenv("LD_PRELOAD", SWM_LIB, 1);
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
if (asprintf(&ret, "%d", ws_idx) == -1) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("spawn: asprintf SWM_WS");
|
2011-06-06 19:52:03 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
setenv("_SWM_WS", ret, 1);
|
|
|
|
free(ret);
|
|
|
|
ret = NULL;
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if (asprintf(&ret, "%d", getpid()) == -1) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("spawn: asprintf _SWM_PID");
|
2011-06-06 19:52:03 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
setenv("_SWM_PID", ret, 1);
|
|
|
|
free(ret);
|
|
|
|
ret = NULL;
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if (setsid() == -1) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("spawn: setsid");
|
2011-06-06 19:52:03 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if (close_fd) {
|
2010-07-15 13:58:25 +00:00
|
|
|
/*
|
|
|
|
* close stdin and stdout to prevent interaction between apps
|
|
|
|
* and the baraction script
|
|
|
|
* leave stderr open to record errors
|
|
|
|
*/
|
|
|
|
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("spawn: open");
|
2010-07-15 13:58:25 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
dup2(fd, STDIN_FILENO);
|
|
|
|
dup2(fd, STDOUT_FILENO);
|
|
|
|
if (fd > 2)
|
|
|
|
close(fd);
|
2011-06-06 19:52:03 +00:00
|
|
|
}
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
execvp(args->argv[0], args->argv);
|
2010-07-15 13:58:25 +00:00
|
|
|
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("spawn: execvp");
|
2011-06-06 19:52:03 +00:00
|
|
|
_exit(1);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 19:49:58 +00:00
|
|
|
void
|
|
|
|
spawnterm(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_MISC, "spawnterm\n");
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
if (fork() == 0) {
|
|
|
|
if (term_width)
|
|
|
|
setenv("_SWM_XTERM_FONTADJ", "", 1);
|
|
|
|
spawn(r->ws->idx, args, 1);
|
|
|
|
}
|
2009-02-07 19:49:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
void
|
|
|
|
kill_refs(struct ws_win *win)
|
|
|
|
{
|
|
|
|
int i, x;
|
|
|
|
struct swm_region *r;
|
|
|
|
struct workspace *ws;
|
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (x = 0; x < workspace_limit; x++) {
|
2009-10-15 20:42:59 +00:00
|
|
|
ws = &r->s->ws[x];
|
|
|
|
if (win == ws->focus)
|
|
|
|
ws->focus = NULL;
|
|
|
|
if (win == ws->focus_prev)
|
|
|
|
ws->focus_prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
validate_win(struct ws_win *testwin)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
struct workspace *ws;
|
|
|
|
struct swm_region *r;
|
2011-12-03 22:35:59 -05:00
|
|
|
int i, x;
|
2009-10-15 20:42:59 +00:00
|
|
|
|
|
|
|
if (testwin == NULL)
|
2011-06-14 22:20:55 +00:00
|
|
|
return (0);
|
2009-10-15 20:42:59 +00:00
|
|
|
|
2011-12-03 22:35:59 -05:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2009-10-15 20:42:59 +00:00
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (x = 0; x < workspace_limit; x++) {
|
2009-10-15 20:42:59 +00:00
|
|
|
ws = &r->s->ws[x];
|
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry)
|
|
|
|
if (win == testwin)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
validate_ws(struct workspace *testws)
|
|
|
|
{
|
|
|
|
struct swm_region *r;
|
|
|
|
struct workspace *ws;
|
2011-12-03 22:35:59 -05:00
|
|
|
int i, x;
|
2009-10-15 20:42:59 +00:00
|
|
|
|
|
|
|
/* validate all ws */
|
2011-12-03 22:35:59 -05:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2009-10-15 20:42:59 +00:00
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (x = 0; x < workspace_limit; x++) {
|
2009-10-15 20:42:59 +00:00
|
|
|
ws = &r->s->ws[x];
|
|
|
|
if (ws == testws)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-03-04 06:13:35 +00:00
|
|
|
void
|
|
|
|
unfocus_win(struct ws_win *win)
|
|
|
|
{
|
2009-11-06 04:41:28 +00:00
|
|
|
XEvent cne;
|
2011-01-18 19:25:58 +00:00
|
|
|
Window none = None;
|
2009-11-06 04:41:28 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "unfocus_win: window: 0x%lx\n", WINID(win));
|
2009-10-23 04:05:19 +00:00
|
|
|
|
2009-03-04 06:13:35 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
2009-10-08 04:50:27 +00:00
|
|
|
if (win->ws == NULL)
|
|
|
|
return;
|
2009-10-15 20:42:59 +00:00
|
|
|
|
|
|
|
if (validate_ws(win->ws))
|
2011-01-18 19:25:58 +00:00
|
|
|
return; /* XXX this gets hit with thunderbird, needs fixing */
|
2009-10-15 20:42:59 +00:00
|
|
|
|
2009-03-04 06:13:35 +00:00
|
|
|
if (win->ws->r == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
if (validate_win(win)) {
|
|
|
|
kill_refs(win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-29 18:59:09 +00:00
|
|
|
if (win->ws->focus == win) {
|
2009-03-04 06:13:35 +00:00
|
|
|
win->ws->focus = NULL;
|
2009-09-29 18:59:09 +00:00
|
|
|
win->ws->focus_prev = win;
|
|
|
|
}
|
2009-10-03 22:20:11 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
if (validate_win(win->ws->focus)) {
|
|
|
|
kill_refs(win->ws->focus);
|
|
|
|
win->ws->focus = NULL;
|
|
|
|
}
|
|
|
|
if (validate_win(win->ws->focus_prev)) {
|
|
|
|
kill_refs(win->ws->focus_prev);
|
|
|
|
win->ws->focus_prev = NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-06 04:41:28 +00:00
|
|
|
/* drain all previous unfocus events */
|
|
|
|
while (XCheckTypedEvent(display, FocusOut, &cne) == True)
|
|
|
|
;
|
|
|
|
|
2009-10-03 22:20:11 +00:00
|
|
|
grabbuttons(win, 0);
|
|
|
|
XSetWindowBorder(display, win->id,
|
|
|
|
win->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
|
2009-11-06 04:41:28 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
XChangeProperty(display, win->s->root,
|
|
|
|
ewmh[_NET_ACTIVE_WINDOW].atom, XA_WINDOW, 32,
|
2012-05-12 21:28:49 +01:00
|
|
|
PropModeReplace, (unsigned char *)&none, 1);
|
2009-03-04 06:13:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 20:21:25 +00:00
|
|
|
void
|
2009-11-06 04:41:28 +00:00
|
|
|
unfocus_all(void)
|
2009-01-13 20:21:25 +00:00
|
|
|
{
|
2009-01-21 23:12:54 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
int i, j;
|
|
|
|
|
2009-11-06 04:41:28 +00:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "unfocus_all\n");
|
2009-01-13 20:21:25 +00:00
|
|
|
|
2009-01-21 23:12:54 +00:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2012-04-08 01:59:41 +08:00
|
|
|
for (j = 0; j < workspace_limit; j++)
|
2009-03-04 06:13:35 +00:00
|
|
|
TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
|
2009-11-06 04:41:28 +00:00
|
|
|
unfocus_win(win);
|
2009-01-21 23:12:54 +00:00
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-13 20:21:25 +00:00
|
|
|
void
|
2009-01-19 05:48:11 +00:00
|
|
|
focus_win(struct ws_win *win)
|
2009-01-13 20:21:25 +00:00
|
|
|
{
|
2009-11-06 04:41:28 +00:00
|
|
|
XEvent cne;
|
|
|
|
Window cur_focus;
|
|
|
|
int rr;
|
|
|
|
struct ws_win *cfw = NULL;
|
|
|
|
|
2009-10-23 04:05:19 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "focus_win: window: 0x%lx\n", WINID(win));
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-21 23:12:54 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
2009-10-08 04:50:27 +00:00
|
|
|
if (win->ws == NULL)
|
|
|
|
return;
|
2009-01-19 09:05:02 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
if (validate_ws(win->ws))
|
2011-01-18 19:25:58 +00:00
|
|
|
return; /* XXX this gets hit with thunderbird, needs fixing */
|
2010-08-11 03:15:40 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
if (validate_win(win)) {
|
|
|
|
kill_refs(win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (validate_win(win)) {
|
|
|
|
kill_refs(win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-06 04:41:28 +00:00
|
|
|
XGetInputFocus(display, &cur_focus, &rr);
|
|
|
|
if ((cfw = find_window(cur_focus)) != NULL)
|
|
|
|
unfocus_win(cfw);
|
2011-06-13 21:51:47 +00:00
|
|
|
else {
|
|
|
|
/* use larger hammer since the window was killed somehow */
|
|
|
|
TAILQ_FOREACH(cfw, &win->ws->winlist, entry)
|
2011-06-16 13:53:43 +00:00
|
|
|
if (cfw->ws && cfw->ws->r && cfw->ws->r->s)
|
|
|
|
XSetWindowBorder(display, cfw->id,
|
|
|
|
cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
|
2011-06-13 21:51:47 +00:00
|
|
|
}
|
2009-11-06 04:41:28 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
win->ws->focus = win;
|
2009-09-29 18:59:09 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
if (win->ws->r != NULL) {
|
2009-11-06 04:41:28 +00:00
|
|
|
/* drain all previous focus events */
|
|
|
|
while (XCheckTypedEvent(display, FocusIn, &cne) == True)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (win->java == 0)
|
|
|
|
XSetInputFocus(display, win->id,
|
|
|
|
RevertToParent, CurrentTime);
|
|
|
|
grabbuttons(win, 1);
|
2009-10-13 02:28:47 +00:00
|
|
|
XSetWindowBorder(display, win->id,
|
|
|
|
win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
|
2011-06-24 16:53:40 +00:00
|
|
|
if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS ||
|
|
|
|
win->ws->always_raise)
|
2009-10-23 04:05:19 +00:00
|
|
|
XMapRaised(display, win->id);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
XChangeProperty(display, win->s->root,
|
|
|
|
ewmh[_NET_ACTIVE_WINDOW].atom, XA_WINDOW, 32,
|
2012-05-12 21:28:49 +01:00
|
|
|
PropModeReplace, (unsigned char *)&win->id, 1);
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
2011-01-18 19:43:12 +00:00
|
|
|
|
2012-05-12 22:05:21 +01:00
|
|
|
bar_update();
|
2009-01-13 20:21:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
switchws(struct swm_region *r, union arg *args)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2010-04-20 19:08:06 +00:00
|
|
|
int wsid = args->id, unmap_old = 0;
|
2009-01-19 05:48:11 +00:00
|
|
|
struct swm_region *this_r, *other_r;
|
2009-10-15 20:42:59 +00:00
|
|
|
struct ws_win *win;
|
2009-01-19 05:48:11 +00:00
|
|
|
struct workspace *new_ws, *old_ws;
|
2009-10-15 20:42:59 +00:00
|
|
|
union arg a;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-10-13 03:43:36 +00:00
|
|
|
if (!(r && r->s))
|
|
|
|
return;
|
2009-10-08 04:40:56 +00:00
|
|
|
|
2012-04-08 01:59:41 +08:00
|
|
|
if (wsid >= workspace_limit)
|
|
|
|
return;
|
|
|
|
|
2009-01-19 09:05:02 +00:00
|
|
|
this_r = r;
|
2009-01-19 05:48:11 +00:00
|
|
|
old_ws = this_r->ws;
|
|
|
|
new_ws = &this_r->s->ws[wsid];
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_WS, "switchws: screen[%d]:%dx%d+%d+%d: %d -> %d\n",
|
|
|
|
r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), old_ws->idx, wsid);
|
2009-01-19 09:05:02 +00:00
|
|
|
|
2009-10-13 03:43:36 +00:00
|
|
|
if (new_ws == NULL || old_ws == NULL)
|
|
|
|
return;
|
2009-10-08 19:21:24 +00:00
|
|
|
if (new_ws == old_ws)
|
2009-09-30 16:45:24 +00:00
|
|
|
return;
|
2009-09-29 18:59:09 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
other_r = new_ws->r;
|
2009-09-30 16:45:24 +00:00
|
|
|
if (other_r == NULL) {
|
2010-07-01 20:58:00 +00:00
|
|
|
/* the other workspace is hidden, hide this one */
|
2009-02-03 02:21:01 +00:00
|
|
|
old_ws->r = NULL;
|
2010-04-20 19:08:06 +00:00
|
|
|
unmap_old = 1;
|
2009-01-19 05:48:11 +00:00
|
|
|
} else {
|
2010-07-01 20:58:00 +00:00
|
|
|
/* the other ws is visible in another region, exchange them */
|
2010-07-01 19:01:15 +00:00
|
|
|
other_r->ws_prior = new_ws;
|
2009-01-19 05:48:11 +00:00
|
|
|
other_r->ws = old_ws;
|
|
|
|
old_ws->r = other_r;
|
|
|
|
}
|
2010-07-01 19:01:15 +00:00
|
|
|
this_r->ws_prior = old_ws;
|
2009-01-19 05:48:11 +00:00
|
|
|
this_r->ws = new_ws;
|
|
|
|
new_ws->r = this_r;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2011-06-14 15:28:05 +00:00
|
|
|
/* this is needed so that we can click on a window after a restart */
|
|
|
|
unfocus_all();
|
|
|
|
|
2009-01-19 09:05:02 +00:00
|
|
|
stack();
|
2009-10-15 20:42:59 +00:00
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(new_ws->r, &a);
|
2011-06-09 21:15:29 +00:00
|
|
|
|
2010-04-20 19:08:06 +00:00
|
|
|
/* unmap old windows */
|
|
|
|
if (unmap_old)
|
|
|
|
TAILQ_FOREACH(win, &old_ws->winlist, entry)
|
|
|
|
unmap_window(win);
|
2011-06-09 21:15:29 +00:00
|
|
|
|
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-21 01:26:56 +00:00
|
|
|
void
|
|
|
|
cyclews(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
union arg a;
|
|
|
|
struct swm_screen *s = r->s;
|
2011-11-28 22:41:58 -05:00
|
|
|
int cycle_all = 0;
|
2009-01-21 01:26:56 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_WS, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
|
|
|
|
args->id, r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
|
2009-01-21 01:26:56 +00:00
|
|
|
|
|
|
|
a.id = r->ws->idx;
|
|
|
|
do {
|
|
|
|
switch (args->id) {
|
2011-11-28 22:41:58 -05:00
|
|
|
case SWM_ARG_ID_CYCLEWS_UP_ALL:
|
|
|
|
cycle_all = 1;
|
|
|
|
/* FALLTHROUGH */
|
2009-01-21 01:26:56 +00:00
|
|
|
case SWM_ARG_ID_CYCLEWS_UP:
|
2012-04-08 01:59:41 +08:00
|
|
|
if (a.id < workspace_limit - 1)
|
2009-01-21 01:26:56 +00:00
|
|
|
a.id++;
|
|
|
|
else
|
|
|
|
a.id = 0;
|
|
|
|
break;
|
2011-11-28 22:41:58 -05:00
|
|
|
case SWM_ARG_ID_CYCLEWS_DOWN_ALL:
|
|
|
|
cycle_all = 1;
|
|
|
|
/* FALLTHROUGH */
|
2009-01-21 01:26:56 +00:00
|
|
|
case SWM_ARG_ID_CYCLEWS_DOWN:
|
|
|
|
if (a.id > 0)
|
|
|
|
a.id--;
|
|
|
|
else
|
2012-04-08 01:59:41 +08:00
|
|
|
a.id = workspace_limit - 1;
|
2009-01-21 01:26:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2011-11-28 22:41:58 -05:00
|
|
|
if (!cycle_all &&
|
|
|
|
(cycle_empty == 0 && TAILQ_EMPTY(&s->ws[a.id].winlist)))
|
2009-01-21 01:26:56 +00:00
|
|
|
continue;
|
|
|
|
if (cycle_visible == 0 && s->ws[a.id].r != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switchws(r, &a);
|
|
|
|
} while (a.id != r->ws->idx);
|
|
|
|
}
|
|
|
|
|
2010-07-01 19:01:15 +00:00
|
|
|
void
|
|
|
|
priorws(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
union arg a;
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_WS, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
|
|
|
|
args->id, r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2010-07-01 19:01:15 +00:00
|
|
|
if (r->ws_prior == NULL)
|
|
|
|
return;
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2010-07-01 19:01:15 +00:00
|
|
|
a.id = r->ws_prior->idx;
|
|
|
|
switchws(r, &a);
|
|
|
|
}
|
|
|
|
|
2009-01-27 19:56:47 +00:00
|
|
|
void
|
|
|
|
cyclescr(struct swm_region *r, union arg *args)
|
|
|
|
{
|
2009-10-03 21:43:07 +00:00
|
|
|
struct swm_region *rr = NULL;
|
2009-10-15 20:42:59 +00:00
|
|
|
union arg a;
|
2009-10-03 21:43:07 +00:00
|
|
|
int i, x, y;
|
2009-01-27 19:56:47 +00:00
|
|
|
|
2009-10-01 21:51:50 +00:00
|
|
|
/* do nothing if we don't have more than one screen */
|
|
|
|
if (!(ScreenCount(display) > 1 || outputs > 1))
|
|
|
|
return;
|
|
|
|
|
2009-01-27 19:56:47 +00:00
|
|
|
i = r->s->idx;
|
|
|
|
switch (args->id) {
|
|
|
|
case SWM_ARG_ID_CYCLESC_UP:
|
|
|
|
rr = TAILQ_NEXT(r, entry);
|
|
|
|
if (rr == NULL)
|
|
|
|
rr = TAILQ_FIRST(&screens[i].rl);
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_CYCLESC_DOWN:
|
|
|
|
rr = TAILQ_PREV(r, swm_region_list, entry);
|
|
|
|
if (rr == NULL)
|
|
|
|
rr = TAILQ_LAST(&screens[i].rl, swm_region_list);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
};
|
2009-10-03 21:43:07 +00:00
|
|
|
if (rr == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
/* move mouse to region */
|
2012-01-29 01:29:31 +08:00
|
|
|
x = X(rr) + 1;
|
|
|
|
y = Y(rr) + 1 + (bar_enabled ? bar_height : 0);
|
2009-10-03 21:43:07 +00:00
|
|
|
XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(rr, &a);
|
|
|
|
|
|
|
|
if (rr->ws->focus) {
|
|
|
|
/* move to focus window */
|
2012-01-29 01:29:31 +08:00
|
|
|
x = X(rr->ws->focus) + 1;
|
|
|
|
y = Y(rr->ws->focus) + 1;
|
2009-10-15 20:42:59 +00:00
|
|
|
XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, x, y);
|
|
|
|
}
|
2009-01-27 19:56:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 22:30:30 +00:00
|
|
|
void
|
|
|
|
sort_windows(struct ws_win_list *wl)
|
|
|
|
{
|
|
|
|
struct ws_win *win, *parent, *nxt;
|
|
|
|
|
|
|
|
if (wl == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (win = TAILQ_FIRST(wl); win != TAILQ_END(wl); win = nxt) {
|
|
|
|
nxt = TAILQ_NEXT(win, entry);
|
|
|
|
if (win->transient) {
|
|
|
|
parent = find_window(win->transient);
|
|
|
|
if (parent == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("not possible bug");
|
2011-06-08 22:30:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(wl, win, entry);
|
|
|
|
TAILQ_INSERT_AFTER(wl, parent, win, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-15 06:41:06 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
swapwin(struct swm_region *r, union arg *args)
|
2009-01-15 06:41:06 +00:00
|
|
|
{
|
2009-02-07 19:21:00 +00:00
|
|
|
struct ws_win *target, *source;
|
2011-06-08 22:30:30 +00:00
|
|
|
struct ws_win *cur_focus;
|
2009-01-19 05:48:11 +00:00
|
|
|
struct ws_win_list *wl;
|
|
|
|
|
2009-01-15 06:41:06 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_WS, "swapwin: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n",
|
|
|
|
args->id, r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx);
|
2009-09-29 14:25:40 +00:00
|
|
|
|
|
|
|
cur_focus = r->ws->focus;
|
2009-01-19 05:48:11 +00:00
|
|
|
if (cur_focus == NULL)
|
2009-01-15 06:41:06 +00:00
|
|
|
return;
|
|
|
|
|
2011-06-08 22:30:30 +00:00
|
|
|
source = cur_focus;
|
2009-02-07 19:21:00 +00:00
|
|
|
wl = &source->ws->winlist;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-15 06:41:06 +00:00
|
|
|
switch (args->id) {
|
|
|
|
case SWM_ARG_ID_SWAPPREV:
|
2011-06-08 22:30:30 +00:00
|
|
|
if (source->transient)
|
|
|
|
source = find_window(source->transient);
|
2009-02-07 19:21:00 +00:00
|
|
|
target = TAILQ_PREV(source, ws_win_list, entry);
|
2011-06-08 22:30:30 +00:00
|
|
|
if (target && target->transient)
|
|
|
|
target = find_window(target->transient);
|
2011-06-08 20:32:03 +00:00
|
|
|
TAILQ_REMOVE(wl, source, entry);
|
2009-01-15 08:27:56 +00:00
|
|
|
if (target == NULL)
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_INSERT_TAIL(wl, source, entry);
|
2009-01-15 08:27:56 +00:00
|
|
|
else
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_INSERT_BEFORE(target, source, entry);
|
2009-01-15 06:41:06 +00:00
|
|
|
break;
|
2009-08-30 18:16:41 +00:00
|
|
|
case SWM_ARG_ID_SWAPNEXT:
|
2009-02-07 19:21:00 +00:00
|
|
|
target = TAILQ_NEXT(source, entry);
|
2011-06-08 22:30:30 +00:00
|
|
|
/* move the parent and let the sort handle the move */
|
|
|
|
if (source->transient)
|
|
|
|
source = find_window(source->transient);
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_REMOVE(wl, source, entry);
|
2009-01-15 08:27:56 +00:00
|
|
|
if (target == NULL)
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_INSERT_HEAD(wl, source, entry);
|
2009-01-15 08:27:56 +00:00
|
|
|
else
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_INSERT_AFTER(wl, target, source, entry);
|
2009-01-15 06:41:06 +00:00
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_SWAPMAIN:
|
2009-01-19 05:48:11 +00:00
|
|
|
target = TAILQ_FIRST(wl);
|
2009-02-07 19:21:00 +00:00
|
|
|
if (target == source) {
|
|
|
|
if (source->ws->focus_prev != NULL &&
|
2009-08-30 18:16:41 +00:00
|
|
|
source->ws->focus_prev != target)
|
2009-02-07 19:21:00 +00:00
|
|
|
source = source->ws->focus_prev;
|
|
|
|
else
|
|
|
|
return;
|
2011-06-14 22:20:55 +00:00
|
|
|
}
|
2009-10-09 18:26:41 +00:00
|
|
|
if (target == NULL || source == NULL)
|
|
|
|
return;
|
2009-02-07 19:21:00 +00:00
|
|
|
source->ws->focus_prev = target;
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_REMOVE(wl, target, entry);
|
2009-02-07 19:21:00 +00:00
|
|
|
TAILQ_INSERT_BEFORE(source, target, entry);
|
|
|
|
TAILQ_REMOVE(wl, source, entry);
|
|
|
|
TAILQ_INSERT_HEAD(wl, source, entry);
|
2009-01-15 06:41:06 +00:00
|
|
|
break;
|
2010-07-01 20:58:00 +00:00
|
|
|
case SWM_ARG_ID_MOVELAST:
|
|
|
|
TAILQ_REMOVE(wl, source, entry);
|
|
|
|
TAILQ_INSERT_TAIL(wl, source, entry);
|
|
|
|
break;
|
2009-01-15 06:41:06 +00:00
|
|
|
default:
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MOVE, "swapwin: invalid id: %d\n", args->id);
|
2009-01-15 06:41:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-08 22:30:30 +00:00
|
|
|
sort_windows(wl);
|
2011-06-08 20:32:03 +00:00
|
|
|
|
2009-01-15 06:41:06 +00:00
|
|
|
stack();
|
|
|
|
}
|
|
|
|
|
2009-10-20 22:42:35 +00:00
|
|
|
void
|
|
|
|
focus_prev(struct ws_win *win)
|
|
|
|
{
|
2012-02-09 20:53:48 +08:00
|
|
|
struct ws_win *winfocus = NULL;
|
2009-10-20 22:42:35 +00:00
|
|
|
struct ws_win *cur_focus = NULL;
|
|
|
|
struct ws_win_list *wl = NULL;
|
|
|
|
struct workspace *ws = NULL;
|
|
|
|
|
|
|
|
if (!(win && win->ws))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ws = win->ws;
|
|
|
|
wl = &ws->winlist;
|
|
|
|
cur_focus = ws->focus;
|
|
|
|
|
2012-05-23 18:31:11 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "focus_prev: window: 0x%lx, cur_focus: 0x%lx\n",
|
|
|
|
WINID(win), WINID(cur_focus));
|
|
|
|
|
2009-10-20 22:42:35 +00:00
|
|
|
/* pickle, just focus on whatever */
|
|
|
|
if (cur_focus == NULL) {
|
|
|
|
/* use prev_focus if valid */
|
|
|
|
if (ws->focus_prev && ws->focus_prev != cur_focus &&
|
|
|
|
find_window(WINID(ws->focus_prev)))
|
|
|
|
winfocus = ws->focus_prev;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if transient focus on parent */
|
|
|
|
if (cur_focus->transient) {
|
|
|
|
winfocus = find_window(cur_focus->transient);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-06-13 20:28:04 +00:00
|
|
|
/* if in max_stack try harder */
|
|
|
|
if ((win->quirks & SWM_Q_FOCUSPREV) ||
|
|
|
|
(ws->cur_layout->flags & SWM_L_FOCUSPREV)) {
|
|
|
|
if (cur_focus != ws->focus_prev)
|
|
|
|
winfocus = ws->focus_prev;
|
|
|
|
else
|
|
|
|
winfocus = TAILQ_PREV(win, ws_win_list, entry);
|
|
|
|
if (winfocus)
|
|
|
|
goto done;
|
2009-10-20 22:42:35 +00:00
|
|
|
}
|
|
|
|
|
2012-05-23 18:31:11 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "focus_prev: focus_close: %d\n", focus_close);
|
2009-10-23 20:56:37 +00:00
|
|
|
|
2012-05-23 18:31:11 +08:00
|
|
|
if (winfocus == NULL || winfocus == win) {
|
|
|
|
switch (focus_close) {
|
|
|
|
case SWM_STACK_BOTTOM:
|
|
|
|
winfocus = TAILQ_FIRST(wl);
|
|
|
|
break;
|
|
|
|
case SWM_STACK_TOP:
|
|
|
|
winfocus = TAILQ_LAST(wl, ws_win_list);
|
|
|
|
break;
|
|
|
|
case SWM_STACK_ABOVE:
|
|
|
|
if ((winfocus = TAILQ_NEXT(cur_focus, entry)) == NULL) {
|
|
|
|
if (focus_close_wrap)
|
|
|
|
winfocus = TAILQ_FIRST(wl);
|
|
|
|
else
|
|
|
|
winfocus = TAILQ_PREV(cur_focus,
|
|
|
|
ws_win_list, entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SWM_STACK_BELOW:
|
|
|
|
if ((winfocus = TAILQ_PREV(cur_focus, ws_win_list,
|
|
|
|
entry)) == NULL) {
|
|
|
|
if (focus_close_wrap)
|
|
|
|
winfocus = TAILQ_LAST(wl, ws_win_list);
|
|
|
|
else
|
|
|
|
winfocus = TAILQ_NEXT(cur_focus, entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-08 01:17:18 +00:00
|
|
|
done:
|
2012-05-23 18:31:11 +08:00
|
|
|
if (winfocus == NULL) {
|
|
|
|
if (focus_default == SWM_STACK_TOP)
|
|
|
|
winfocus = TAILQ_LAST(wl, ws_win_list);
|
|
|
|
else
|
|
|
|
winfocus = TAILQ_FIRST(wl);
|
|
|
|
}
|
|
|
|
|
2012-05-12 22:17:22 +01:00
|
|
|
kill_refs(win);
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(winfocus);
|
2009-10-20 22:42:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
focus(struct swm_region *r, union arg *args)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2012-02-09 20:53:48 +08:00
|
|
|
struct ws_win *winfocus = NULL, *head;
|
2009-10-16 04:28:40 +00:00
|
|
|
struct ws_win *cur_focus = NULL;
|
|
|
|
struct ws_win_list *wl = NULL;
|
|
|
|
struct workspace *ws = NULL;
|
2012-01-09 20:30:00 -05:00
|
|
|
int all_iconics;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
if (!(r && r->ws))
|
|
|
|
return;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "focus: id: %d\n", args->id);
|
2009-09-29 14:25:40 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
/* treat FOCUS_CUR special */
|
|
|
|
if (args->id == SWM_ARG_ID_FOCUSCUR) {
|
2011-06-06 19:52:03 +00:00
|
|
|
if (r->ws->focus && r->ws->focus->iconic == 0)
|
2009-10-15 20:42:59 +00:00
|
|
|
winfocus = r->ws->focus;
|
2011-06-06 19:52:03 +00:00
|
|
|
else if (r->ws->focus_prev && r->ws->focus_prev->iconic == 0)
|
2009-10-15 20:42:59 +00:00
|
|
|
winfocus = r->ws->focus_prev;
|
|
|
|
else
|
2011-06-06 19:52:03 +00:00
|
|
|
TAILQ_FOREACH(winfocus, &r->ws->winlist, entry)
|
|
|
|
if (winfocus->iconic == 0)
|
|
|
|
break;
|
2009-10-23 20:56:37 +00:00
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(winfocus);
|
2009-10-15 20:42:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-20 22:42:35 +00:00
|
|
|
if ((cur_focus = r->ws->focus) == NULL)
|
2009-01-13 15:55:13 +00:00
|
|
|
return;
|
2009-10-16 04:28:40 +00:00
|
|
|
ws = r->ws;
|
|
|
|
wl = &ws->winlist;
|
2012-01-09 20:30:00 -05:00
|
|
|
if (TAILQ_EMPTY(wl))
|
|
|
|
return;
|
|
|
|
/* make sure there is at least one uniconified window */
|
|
|
|
all_iconics = 1;
|
|
|
|
TAILQ_FOREACH(winfocus, wl, entry)
|
|
|
|
if (winfocus->iconic == 0) {
|
|
|
|
all_iconics = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (all_iconics)
|
|
|
|
return;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
switch (args->id) {
|
2010-08-11 03:15:40 +00:00
|
|
|
case SWM_ARG_ID_FOCUSPREV:
|
2011-06-06 19:52:03 +00:00
|
|
|
head = TAILQ_PREV(cur_focus, ws_win_list, entry);
|
|
|
|
if (head == NULL)
|
|
|
|
head = TAILQ_LAST(wl, ws_win_list);
|
|
|
|
winfocus = head;
|
2011-06-07 20:56:29 +00:00
|
|
|
if (WINID(winfocus) == cur_focus->transient) {
|
|
|
|
head = TAILQ_PREV(winfocus, ws_win_list, entry);
|
|
|
|
if (head == NULL)
|
|
|
|
head = TAILQ_LAST(wl, ws_win_list);
|
|
|
|
winfocus = head;
|
2011-06-06 19:52:03 +00:00
|
|
|
}
|
2011-06-08 19:19:45 +00:00
|
|
|
|
|
|
|
/* skip iconics */
|
|
|
|
if (winfocus && winfocus->iconic) {
|
2012-01-04 21:32:16 -05:00
|
|
|
while (winfocus != cur_focus) {
|
|
|
|
if (winfocus == NULL)
|
|
|
|
winfocus = TAILQ_LAST(wl, ws_win_list);
|
2011-06-08 19:19:45 +00:00
|
|
|
if (winfocus->iconic == 0)
|
|
|
|
break;
|
2012-01-29 01:29:31 +08:00
|
|
|
winfocus = TAILQ_PREV(winfocus, ws_win_list,
|
|
|
|
entry);
|
2012-01-04 21:32:16 -05:00
|
|
|
}
|
2011-06-08 19:19:45 +00:00
|
|
|
}
|
2009-10-16 04:28:40 +00:00
|
|
|
break;
|
2009-10-20 22:42:35 +00:00
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
case SWM_ARG_ID_FOCUSNEXT:
|
2011-06-06 19:52:03 +00:00
|
|
|
head = TAILQ_NEXT(cur_focus, entry);
|
|
|
|
if (head == NULL)
|
|
|
|
head = TAILQ_FIRST(wl);
|
|
|
|
winfocus = head;
|
2011-06-08 19:19:45 +00:00
|
|
|
|
|
|
|
/* skip iconics */
|
|
|
|
if (winfocus && winfocus->iconic) {
|
2012-01-04 21:32:16 -05:00
|
|
|
while (winfocus != cur_focus) {
|
|
|
|
if (winfocus == NULL)
|
|
|
|
winfocus = TAILQ_FIRST(wl);
|
2011-06-08 19:19:45 +00:00
|
|
|
if (winfocus->iconic == 0)
|
|
|
|
break;
|
2012-01-04 21:32:16 -05:00
|
|
|
winfocus = TAILQ_NEXT(winfocus, entry);
|
|
|
|
}
|
2011-06-08 19:19:45 +00:00
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SWM_ARG_ID_FOCUSMAIN:
|
2009-01-19 05:48:11 +00:00
|
|
|
winfocus = TAILQ_FIRST(wl);
|
2009-02-13 00:47:21 +00:00
|
|
|
if (winfocus == cur_focus)
|
|
|
|
winfocus = cur_focus->ws->focus_prev;
|
2009-01-13 15:55:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-01-15 06:41:06 +00:00
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(winfocus);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
cycle_layout(struct swm_region *r, union arg *args)
|
2009-01-15 13:59:58 +00:00
|
|
|
{
|
2009-01-19 14:15:31 +00:00
|
|
|
struct workspace *ws = r->ws;
|
2009-10-15 20:42:59 +00:00
|
|
|
union arg a;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_EVENT, "cycle_layout: workspace: %d\n", ws->idx);
|
2009-01-15 13:59:58 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
ws->cur_layout++;
|
|
|
|
if (ws->cur_layout->l_stack == NULL)
|
|
|
|
ws->cur_layout = &layouts[0];
|
2009-09-30 18:08:58 +00:00
|
|
|
|
2009-01-15 13:59:58 +00:00
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-10-15 20:42:59 +00:00
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(r, &a);
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 07:27:26 +00:00
|
|
|
void
|
2009-01-20 05:37:45 +00:00
|
|
|
stack_config(struct swm_region *r, union arg *args)
|
2009-01-16 07:27:26 +00:00
|
|
|
{
|
2009-01-19 09:05:02 +00:00
|
|
|
struct workspace *ws = r->ws;
|
2009-01-16 07:27:26 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_STACK, "stack_config: id: %d workspace: %d\n",
|
2009-01-19 05:48:11 +00:00
|
|
|
args->id, ws->idx);
|
|
|
|
|
2009-01-20 05:37:45 +00:00
|
|
|
if (ws->cur_layout->l_config != NULL)
|
|
|
|
ws->cur_layout->l_config(ws, args->id);
|
2009-01-16 07:27:26 +00:00
|
|
|
|
2011-06-22 15:31:27 +00:00
|
|
|
if (args->id != SWM_ARG_ID_STACKINIT)
|
2009-01-16 07:27:26 +00:00
|
|
|
stack();
|
2011-07-19 21:28:15 +00:00
|
|
|
bar_update();
|
2009-01-16 07:27:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 13:59:58 +00:00
|
|
|
void
|
|
|
|
stack(void) {
|
2009-01-19 14:15:31 +00:00
|
|
|
struct swm_geometry g;
|
|
|
|
struct swm_region *r;
|
2012-01-22 03:38:04 +08:00
|
|
|
int i;
|
|
|
|
#ifdef SWM_DEBUG
|
|
|
|
int j;
|
|
|
|
#endif
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_STACK, "stack: begin\n");
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
2012-01-22 03:38:04 +08:00
|
|
|
#ifdef SWM_DEBUG
|
2011-12-04 22:15:06 -05:00
|
|
|
j = 0;
|
2012-01-22 03:38:04 +08:00
|
|
|
#endif
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_STACK, "stack: workspace: %d "
|
|
|
|
"(screen: %d, region: %d)\n", r->ws->idx, i, j++);
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
/* start with screen geometry, adjust for bar */
|
|
|
|
g = r->g;
|
2011-03-11 14:12:49 +00:00
|
|
|
g.w -= 2 * border_width;
|
|
|
|
g.h -= 2 * border_width;
|
2009-01-19 05:48:11 +00:00
|
|
|
if (bar_enabled) {
|
2010-07-15 14:05:16 +00:00
|
|
|
if (!bar_at_bottom)
|
2010-07-15 14:03:04 +00:00
|
|
|
g.y += bar_height;
|
2009-01-19 05:48:11 +00:00
|
|
|
g.h -= bar_height;
|
2009-08-30 18:16:41 +00:00
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
r->ws->cur_layout->l_stack(r->ws, &g);
|
2011-07-19 21:28:15 +00:00
|
|
|
r->ws->cur_layout->l_string(r->ws);
|
2010-07-01 20:58:00 +00:00
|
|
|
/* save r so we can track region changes */
|
|
|
|
r->ws->old_r = r;
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-07 19:49:58 +00:00
|
|
|
if (font_adjusted)
|
|
|
|
font_adjusted--;
|
2011-06-09 21:15:29 +00:00
|
|
|
|
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2012-01-29 01:29:31 +08:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_STACK, "stack: end\n");
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
void
|
|
|
|
store_float_geom(struct ws_win *win, struct swm_region *r)
|
|
|
|
{
|
|
|
|
/* retain window geom and region geom */
|
2012-01-29 01:29:31 +08:00
|
|
|
win->g_float = win->g;
|
|
|
|
win->rg_float = r->g;
|
2010-07-01 20:58:00 +00:00
|
|
|
win->g_floatvalid = 1;
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:21:55 +00:00
|
|
|
void
|
2009-01-19 05:48:11 +00:00
|
|
|
stack_floater(struct ws_win *win, struct swm_region *r)
|
2009-01-15 19:21:55 +00:00
|
|
|
{
|
|
|
|
unsigned int mask;
|
|
|
|
XWindowChanges wc;
|
|
|
|
|
2009-10-01 15:17:17 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-01-15 19:21:55 +00:00
|
|
|
bzero(&wc, sizeof wc);
|
2009-01-18 03:30:51 +00:00
|
|
|
mask = CWX | CWY | CWBorderWidth | CWWidth | CWHeight;
|
2010-07-01 20:58:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* to allow windows to change their size (e.g. mplayer fs) only retrieve
|
|
|
|
* geom on ws switches or return from max mode
|
|
|
|
*/
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->floatmaxed || (r != r->ws->old_r && win->g_floatvalid
|
|
|
|
&& !(win->ewmh_flags & EWMH_F_FULLSCREEN))) {
|
2010-07-01 20:58:00 +00:00
|
|
|
/*
|
|
|
|
* use stored g and rg to set relative position and size
|
|
|
|
* as in old region or before max stack mode
|
|
|
|
*/
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = win->g_float.x - win->rg_float.x + X(r);
|
|
|
|
Y(win) = win->g_float.y - win->rg_float.y + Y(r);
|
|
|
|
WIDTH(win) = win->g_float.w;
|
|
|
|
HEIGHT(win) = win->g_float.h;
|
2010-07-01 20:58:00 +00:00
|
|
|
win->g_floatvalid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
win->floatmaxed = 0;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if ((win->quirks & SWM_Q_FULLSCREEN) && (WIDTH(win) >= WIDTH(r)) &&
|
|
|
|
(HEIGHT(win) >= HEIGHT(r)))
|
2009-02-11 06:02:24 +00:00
|
|
|
wc.border_width = 0;
|
|
|
|
else
|
2011-03-11 14:12:49 +00:00
|
|
|
wc.border_width = border_width;
|
2009-02-03 00:50:01 +00:00
|
|
|
if (win->transient && (win->quirks & SWM_Q_TRANSSZ)) {
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = (double)WIDTH(r) * dialog_ratio;
|
|
|
|
HEIGHT(win) = (double)HEIGHT(r) * dialog_ratio;
|
2009-01-15 19:21:55 +00:00
|
|
|
}
|
2010-07-01 20:58:00 +00:00
|
|
|
|
|
|
|
if (!win->manual) {
|
|
|
|
/*
|
|
|
|
* floaters and transients are auto-centred unless moved
|
|
|
|
* or resized
|
|
|
|
*/
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = X(r) + (WIDTH(r) - WIDTH(win)) / 2 - wc.border_width;
|
|
|
|
Y(win) = Y(r) + (HEIGHT(r) - HEIGHT(win)) / 2 - wc.border_width;
|
2010-07-01 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* win can be outside r if new r smaller than old r */
|
|
|
|
/* Ensure top left corner inside r (move probs otherwise) */
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) < X(r) - wc.border_width)
|
|
|
|
X(win) = X(r) - wc.border_width;
|
|
|
|
if (X(win) > X(r) + WIDTH(r) - 1)
|
|
|
|
X(win) = (WIDTH(win) > WIDTH(r)) ? X(r) :
|
|
|
|
(X(r) + WIDTH(r) - WIDTH(win) - 2 * wc.border_width);
|
|
|
|
if (Y(win) < Y(r) - wc.border_width)
|
|
|
|
Y(win) = Y(r) - wc.border_width;
|
|
|
|
if (Y(win) > Y(r) + HEIGHT(r) - 1)
|
|
|
|
Y(win) = (HEIGHT(win) > HEIGHT(r)) ? Y(r) :
|
|
|
|
(Y(r) + HEIGHT(r) - HEIGHT(win) - 2 * wc.border_width);
|
|
|
|
|
|
|
|
wc.x = X(win);
|
|
|
|
wc.y = Y(win);
|
|
|
|
wc.width = WIDTH(win);
|
|
|
|
wc.height = HEIGHT(win);
|
2009-09-30 20:15:02 +00:00
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
/*
|
|
|
|
* Retain floater and transient geometry for correct positioning
|
|
|
|
* when ws changes region
|
|
|
|
*/
|
2010-09-16 02:26:45 +00:00
|
|
|
if (!(win->ewmh_flags & EWMH_F_FULLSCREEN))
|
|
|
|
store_float_geom(win, r);
|
2009-10-13 14:32:18 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "stack_floater: window: %lu, (x,y) w x h: (%d,%d) "
|
|
|
|
"%d x %d\n", win->id, wc.x, wc.y, wc.width, wc.height);
|
2009-01-15 19:21:55 +00:00
|
|
|
|
|
|
|
XConfigureWindow(display, win->id, mask, &wc);
|
|
|
|
}
|
|
|
|
|
2009-02-07 19:49:58 +00:00
|
|
|
/*
|
|
|
|
* Send keystrokes to terminal to decrease/increase the font size as the
|
|
|
|
* window size changes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
adjust_font(struct ws_win *win)
|
|
|
|
{
|
|
|
|
if (!(win->quirks & SWM_Q_XTERM_FONTADJ) ||
|
|
|
|
win->floating || win->transient)
|
|
|
|
return;
|
2009-08-30 18:16:41 +00:00
|
|
|
|
2009-02-07 19:49:58 +00:00
|
|
|
if (win->sh.width_inc && win->last_inc != win->sh.width_inc &&
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) / win->sh.width_inc < term_width &&
|
2009-02-07 19:49:58 +00:00
|
|
|
win->font_steps < SWM_MAX_FONT_STEPS) {
|
|
|
|
win->font_size_boundary[win->font_steps] =
|
|
|
|
(win->sh.width_inc * term_width) + win->sh.base_width;
|
|
|
|
win->font_steps++;
|
|
|
|
font_adjusted++;
|
|
|
|
win->last_inc = win->sh.width_inc;
|
|
|
|
fake_keypress(win, XK_KP_Subtract, ShiftMask);
|
|
|
|
} else if (win->font_steps && win->last_inc != win->sh.width_inc &&
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) > win->font_size_boundary[win->font_steps - 1]) {
|
2009-02-07 19:49:58 +00:00
|
|
|
win->font_steps--;
|
|
|
|
font_adjusted++;
|
|
|
|
win->last_inc = win->sh.width_inc;
|
|
|
|
fake_keypress(win, XK_KP_Add, ShiftMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-25 10:43:20 +00:00
|
|
|
#define SWAPXY(g) do { \
|
|
|
|
int tmp; \
|
|
|
|
tmp = (g)->y; (g)->y = (g)->x; (g)->x = tmp; \
|
|
|
|
tmp = (g)->h; (g)->h = (g)->w; (g)->w = tmp; \
|
2009-01-25 17:56:01 +00:00
|
|
|
} while (0)
|
2009-01-16 07:27:26 +00:00
|
|
|
void
|
2009-01-25 10:43:20 +00:00
|
|
|
stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
|
|
|
XWindowChanges wc;
|
2009-11-06 04:41:28 +00:00
|
|
|
XWindowAttributes wa;
|
2009-01-25 10:43:20 +00:00
|
|
|
struct swm_geometry win_g, r_g = *g;
|
2010-09-16 02:26:45 +00:00
|
|
|
struct ws_win *win, *fs_win = 0;
|
2009-08-30 18:16:41 +00:00
|
|
|
int i, j, s, stacks;
|
2009-02-09 04:12:09 +00:00
|
|
|
int w_inc = 1, h_inc, w_base = 1, h_base;
|
2009-02-09 04:40:11 +00:00
|
|
|
int hrh, extra = 0, h_slice, last_h = 0;
|
2009-01-25 17:56:01 +00:00
|
|
|
int split, colno, winno, mwin, msize, mscale;
|
2009-10-12 04:09:17 +00:00
|
|
|
int remain, missing, v_slice, reconfigure;
|
2009-01-15 19:21:55 +00:00
|
|
|
unsigned int mask;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_STACK, "stack_master: workspace: %d, rot: %s, "
|
|
|
|
"flip: %s\n", ws->idx, YESNO(rot), YESNO(flip));
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-09-23 03:34:58 +00:00
|
|
|
winno = count_win(ws, 0);
|
|
|
|
if (winno == 0 && count_win(ws, 1) == 0)
|
2009-01-13 15:55:13 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-09 04:12:09 +00:00
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry)
|
2011-06-14 22:20:55 +00:00
|
|
|
if (win->transient == 0 && win->floating == 0
|
|
|
|
&& win->iconic == 0)
|
2009-02-09 04:12:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
goto notiles;
|
|
|
|
|
2009-01-25 10:43:20 +00:00
|
|
|
if (rot) {
|
2009-01-25 17:56:01 +00:00
|
|
|
w_inc = win->sh.width_inc;
|
|
|
|
w_base = win->sh.base_width;
|
2009-01-25 10:43:20 +00:00
|
|
|
mwin = ws->l_state.horizontal_mwin;
|
|
|
|
mscale = ws->l_state.horizontal_msize;
|
2009-02-03 13:13:30 +00:00
|
|
|
stacks = ws->l_state.horizontal_stacks;
|
2009-01-25 10:43:20 +00:00
|
|
|
SWAPXY(&r_g);
|
|
|
|
} else {
|
2009-01-25 17:56:01 +00:00
|
|
|
w_inc = win->sh.height_inc;
|
|
|
|
w_base = win->sh.base_height;
|
2009-01-25 10:43:20 +00:00
|
|
|
mwin = ws->l_state.vertical_mwin;
|
|
|
|
mscale = ws->l_state.vertical_msize;
|
2009-02-03 13:13:30 +00:00
|
|
|
stacks = ws->l_state.vertical_stacks;
|
2009-01-25 10:43:20 +00:00
|
|
|
}
|
|
|
|
win_g = r_g;
|
|
|
|
|
2009-02-03 13:13:30 +00:00
|
|
|
if (stacks > winno - mwin)
|
|
|
|
stacks = winno - mwin;
|
2009-02-04 08:58:54 +00:00
|
|
|
if (stacks < 1)
|
|
|
|
stacks = 1;
|
2009-02-03 13:13:30 +00:00
|
|
|
|
2009-01-25 17:56:01 +00:00
|
|
|
h_slice = r_g.h / SWM_H_SLICE;
|
2009-01-25 10:43:20 +00:00
|
|
|
if (mwin && winno > mwin) {
|
2009-01-25 21:48:06 +00:00
|
|
|
v_slice = r_g.w / SWM_V_SLICE;
|
2009-01-25 17:56:01 +00:00
|
|
|
|
2009-01-25 10:43:20 +00:00
|
|
|
split = mwin;
|
2009-01-20 05:37:45 +00:00
|
|
|
colno = split;
|
2009-02-03 13:13:30 +00:00
|
|
|
win_g.w = v_slice * mscale;
|
2009-01-25 17:56:01 +00:00
|
|
|
|
|
|
|
if (w_inc > 1 && w_inc < v_slice) {
|
|
|
|
/* adjust for window's requested size increment */
|
2009-01-25 21:48:06 +00:00
|
|
|
remain = (win_g.w - w_base) % w_inc;
|
2009-02-09 04:40:11 +00:00
|
|
|
win_g.w -= remain;
|
2009-01-25 17:56:01 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 13:13:30 +00:00
|
|
|
msize = win_g.w;
|
2009-08-30 18:16:41 +00:00
|
|
|
if (flip)
|
2009-01-25 10:54:16 +00:00
|
|
|
win_g.x += r_g.w - msize;
|
2009-01-20 05:37:45 +00:00
|
|
|
} else {
|
2009-02-04 08:58:54 +00:00
|
|
|
msize = -2;
|
|
|
|
colno = split = winno / stacks;
|
2011-06-14 22:20:55 +00:00
|
|
|
win_g.w = ((r_g.w - (stacks * 2 * border_width) +
|
|
|
|
2 * border_width) / stacks);
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
2009-01-25 10:43:20 +00:00
|
|
|
hrh = r_g.h / colno;
|
2009-01-25 17:56:01 +00:00
|
|
|
extra = r_g.h - (colno * hrh);
|
2011-03-11 14:12:49 +00:00
|
|
|
win_g.h = hrh - 2 * border_width;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-02-01 01:39:25 +00:00
|
|
|
/* stack all the tiled windows */
|
2009-02-03 13:13:30 +00:00
|
|
|
i = j = 0, s = stacks;
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry) {
|
2009-02-01 01:39:25 +00:00
|
|
|
if (win->transient != 0 || win->floating != 0)
|
|
|
|
continue;
|
2011-06-06 19:52:03 +00:00
|
|
|
if (win->iconic != 0)
|
|
|
|
continue;
|
2009-02-01 01:39:25 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->ewmh_flags & EWMH_F_FULLSCREEN) {
|
|
|
|
fs_win = win;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-01-20 05:37:45 +00:00
|
|
|
if (split && i == split) {
|
2009-02-03 14:49:40 +00:00
|
|
|
colno = (winno - mwin) / stacks;
|
|
|
|
if (s <= (winno - mwin) % stacks)
|
|
|
|
colno++;
|
2009-02-03 13:13:30 +00:00
|
|
|
split = split + colno;
|
2009-01-25 10:43:20 +00:00
|
|
|
hrh = (r_g.h / colno);
|
2009-01-25 17:56:01 +00:00
|
|
|
extra = r_g.h - (colno * hrh);
|
2009-01-25 10:54:16 +00:00
|
|
|
if (flip)
|
|
|
|
win_g.x = r_g.x;
|
|
|
|
else
|
2011-03-11 14:12:49 +00:00
|
|
|
win_g.x += win_g.w + 2 * border_width;
|
2011-06-14 22:20:55 +00:00
|
|
|
win_g.w = (r_g.w - msize -
|
|
|
|
(stacks * 2 * border_width)) / stacks;
|
2009-02-03 14:49:40 +00:00
|
|
|
if (s == 1)
|
2011-06-14 22:20:55 +00:00
|
|
|
win_g.w += (r_g.w - msize -
|
|
|
|
(stacks * 2 * border_width)) % stacks;
|
2009-02-03 13:13:30 +00:00
|
|
|
s--;
|
2009-01-20 05:37:45 +00:00
|
|
|
j = 0;
|
2009-01-20 06:05:47 +00:00
|
|
|
}
|
2011-03-11 14:12:49 +00:00
|
|
|
win_g.h = hrh - 2 * border_width;
|
2009-01-25 17:56:01 +00:00
|
|
|
if (rot) {
|
|
|
|
h_inc = win->sh.width_inc;
|
|
|
|
h_base = win->sh.base_width;
|
|
|
|
} else {
|
2009-08-30 18:16:41 +00:00
|
|
|
h_inc = win->sh.height_inc;
|
2009-01-25 17:56:01 +00:00
|
|
|
h_base = win->sh.base_height;
|
|
|
|
}
|
|
|
|
if (j == colno - 1) {
|
|
|
|
win_g.h = hrh + extra;
|
|
|
|
} else if (h_inc > 1 && h_inc < h_slice) {
|
|
|
|
/* adjust for window's requested size increment */
|
2009-01-25 21:48:06 +00:00
|
|
|
remain = (win_g.h - h_base) % h_inc;
|
|
|
|
missing = h_inc - remain;
|
2009-01-25 17:56:01 +00:00
|
|
|
|
|
|
|
if (missing <= extra || j == 0) {
|
|
|
|
extra -= missing;
|
|
|
|
win_g.h += missing;
|
|
|
|
} else {
|
|
|
|
win_g.h -= remain;
|
|
|
|
extra += remain;
|
|
|
|
}
|
|
|
|
}
|
2009-08-30 18:16:41 +00:00
|
|
|
|
2009-01-20 05:37:45 +00:00
|
|
|
if (j == 0)
|
2009-01-25 10:43:20 +00:00
|
|
|
win_g.y = r_g.y;
|
2009-01-20 05:37:45 +00:00
|
|
|
else
|
2011-03-11 14:12:49 +00:00
|
|
|
win_g.y += last_h + 2 * border_width;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-02-01 01:39:25 +00:00
|
|
|
bzero(&wc, sizeof wc);
|
2010-07-01 23:44:16 +00:00
|
|
|
if (disable_border && bar_enabled == 0 && winno == 1){
|
2010-07-01 21:13:02 +00:00
|
|
|
wc.border_width = 0;
|
2011-03-11 14:12:49 +00:00
|
|
|
win_g.w += 2 * border_width;
|
|
|
|
win_g.h += 2 * border_width;
|
2010-07-01 21:13:02 +00:00
|
|
|
} else
|
2011-03-11 14:12:49 +00:00
|
|
|
wc.border_width = border_width;
|
2009-10-12 04:09:17 +00:00
|
|
|
reconfigure = 0;
|
2009-02-01 01:39:25 +00:00
|
|
|
if (rot) {
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) != win_g.y || Y(win) != win_g.x ||
|
|
|
|
WIDTH(win) != win_g.h || HEIGHT(win) != win_g.w) {
|
2009-10-12 04:09:17 +00:00
|
|
|
reconfigure = 1;
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = wc.x = win_g.y;
|
|
|
|
Y(win) = wc.y = win_g.x;
|
|
|
|
WIDTH(win) = wc.width = win_g.h;
|
|
|
|
HEIGHT(win) = wc.height = win_g.w;
|
2009-10-12 04:09:17 +00:00
|
|
|
}
|
2009-02-01 01:39:25 +00:00
|
|
|
} else {
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) != win_g.x || Y(win) != win_g.y ||
|
|
|
|
WIDTH(win) != win_g.w || HEIGHT(win) != win_g.h) {
|
2009-10-12 04:09:17 +00:00
|
|
|
reconfigure = 1;
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = wc.x = win_g.x;
|
|
|
|
Y(win) = wc.y = win_g.y;
|
|
|
|
WIDTH(win) = wc.width = win_g.w;
|
|
|
|
HEIGHT(win) = wc.height = win_g.h;
|
2009-10-12 04:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reconfigure) {
|
|
|
|
adjust_font(win);
|
|
|
|
mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
|
|
|
|
XConfigureWindow(display, win->id, mask, &wc);
|
2009-01-14 22:06:48 +00:00
|
|
|
}
|
2009-11-06 04:41:28 +00:00
|
|
|
|
|
|
|
if (XGetWindowAttributes(display, win->id, &wa))
|
|
|
|
if (wa.map_state == IsUnmapped)
|
|
|
|
XMapRaised(display, win->id);
|
2009-02-01 01:39:25 +00:00
|
|
|
|
2009-01-25 17:56:01 +00:00
|
|
|
last_h = win_g.h;
|
2009-01-13 15:55:13 +00:00
|
|
|
i++;
|
2009-01-20 05:37:45 +00:00
|
|
|
j++;
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2011-06-08 19:05:43 +00:00
|
|
|
notiles:
|
2009-02-01 01:39:25 +00:00
|
|
|
/* now, stack all the floaters and transients */
|
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry) {
|
|
|
|
if (win->transient == 0 && win->floating == 0)
|
|
|
|
continue;
|
2011-06-08 19:05:43 +00:00
|
|
|
if (win->iconic == 1)
|
2011-06-06 19:52:03 +00:00
|
|
|
continue;
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->ewmh_flags & EWMH_F_FULLSCREEN) {
|
|
|
|
fs_win = win;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-02-01 01:39:25 +00:00
|
|
|
stack_floater(win, ws->r);
|
|
|
|
XMapRaised(display, win->id);
|
|
|
|
}
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (fs_win) {
|
|
|
|
stack_floater(fs_win, ws->r);
|
|
|
|
XMapRaised(display, fs_win->id);
|
|
|
|
}
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 10:43:20 +00:00
|
|
|
void
|
|
|
|
vertical_config(struct workspace *ws, int id)
|
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_STACK, "vertical_config: id: %d, workspace: %d\n",
|
|
|
|
id, ws->idx);
|
2009-01-25 10:43:20 +00:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case SWM_ARG_ID_STACKRESET:
|
|
|
|
case SWM_ARG_ID_STACKINIT:
|
|
|
|
ws->l_state.vertical_msize = SWM_V_SLICE / 2;
|
|
|
|
ws->l_state.vertical_mwin = 1;
|
2009-02-03 13:13:30 +00:00
|
|
|
ws->l_state.vertical_stacks = 1;
|
2009-01-25 10:43:20 +00:00
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERSHRINK:
|
|
|
|
if (ws->l_state.vertical_msize > 1)
|
|
|
|
ws->l_state.vertical_msize--;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERGROW:
|
|
|
|
if (ws->l_state.vertical_msize < SWM_V_SLICE - 1)
|
|
|
|
ws->l_state.vertical_msize++;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERADD:
|
|
|
|
ws->l_state.vertical_mwin++;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERDEL:
|
|
|
|
if (ws->l_state.vertical_mwin > 0)
|
|
|
|
ws->l_state.vertical_mwin--;
|
2009-02-04 08:58:54 +00:00
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_STACKINC:
|
2009-02-03 13:13:30 +00:00
|
|
|
ws->l_state.vertical_stacks++;
|
|
|
|
break;
|
2009-02-04 08:58:54 +00:00
|
|
|
case SWM_ARG_ID_STACKDEC:
|
2009-02-03 13:13:30 +00:00
|
|
|
if (ws->l_state.vertical_stacks > 1)
|
|
|
|
ws->l_state.vertical_stacks--;
|
2009-01-25 10:43:20 +00:00
|
|
|
break;
|
2012-02-08 01:17:20 +08:00
|
|
|
case SWM_ARG_ID_FLIPLAYOUT:
|
|
|
|
ws->l_state.vertical_flip = !ws->l_state.vertical_flip;
|
|
|
|
break;
|
2009-01-25 10:43:20 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vertical_stack(struct workspace *ws, struct swm_geometry *g)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_STACK, "vertical_stack: workspace: %d\n", ws->idx);
|
|
|
|
|
2012-02-08 01:17:20 +08:00
|
|
|
stack_master(ws, g, 0, ws->l_state.vertical_flip);
|
2009-01-25 10:43:20 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 13:59:58 +00:00
|
|
|
void
|
2009-01-20 05:37:45 +00:00
|
|
|
horizontal_config(struct workspace *ws, int id)
|
2009-01-16 07:27:26 +00:00
|
|
|
{
|
2009-01-20 05:37:45 +00:00
|
|
|
DNPRINTF(SWM_D_STACK, "horizontal_config: workspace: %d\n", ws->idx);
|
2009-01-16 07:27:26 +00:00
|
|
|
|
|
|
|
switch (id) {
|
2009-01-20 05:37:45 +00:00
|
|
|
case SWM_ARG_ID_STACKRESET:
|
|
|
|
case SWM_ARG_ID_STACKINIT:
|
|
|
|
ws->l_state.horizontal_mwin = 1;
|
|
|
|
ws->l_state.horizontal_msize = SWM_H_SLICE / 2;
|
2009-02-03 13:13:30 +00:00
|
|
|
ws->l_state.horizontal_stacks = 1;
|
2009-01-20 05:37:45 +00:00
|
|
|
break;
|
2009-01-16 07:27:26 +00:00
|
|
|
case SWM_ARG_ID_MASTERSHRINK:
|
2009-01-20 05:37:45 +00:00
|
|
|
if (ws->l_state.horizontal_msize > 1)
|
|
|
|
ws->l_state.horizontal_msize--;
|
2009-01-16 07:27:26 +00:00
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERGROW:
|
2009-01-20 05:37:45 +00:00
|
|
|
if (ws->l_state.horizontal_msize < SWM_H_SLICE - 1)
|
|
|
|
ws->l_state.horizontal_msize++;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERADD:
|
|
|
|
ws->l_state.horizontal_mwin++;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MASTERDEL:
|
|
|
|
if (ws->l_state.horizontal_mwin > 0)
|
|
|
|
ws->l_state.horizontal_mwin--;
|
2009-01-16 07:27:26 +00:00
|
|
|
break;
|
2009-02-04 08:58:54 +00:00
|
|
|
case SWM_ARG_ID_STACKINC:
|
2009-02-03 13:13:30 +00:00
|
|
|
ws->l_state.horizontal_stacks++;
|
|
|
|
break;
|
2009-02-04 08:58:54 +00:00
|
|
|
case SWM_ARG_ID_STACKDEC:
|
2009-02-03 13:13:30 +00:00
|
|
|
if (ws->l_state.horizontal_stacks > 1)
|
|
|
|
ws->l_state.horizontal_stacks--;
|
2009-02-04 08:58:54 +00:00
|
|
|
break;
|
2012-02-08 01:17:20 +08:00
|
|
|
case SWM_ARG_ID_FLIPLAYOUT:
|
|
|
|
ws->l_state.horizontal_flip = !ws->l_state.horizontal_flip;
|
|
|
|
break;
|
2009-01-16 07:27:26 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-25 10:43:20 +00:00
|
|
|
horizontal_stack(struct workspace *ws, struct swm_geometry *g)
|
|
|
|
{
|
2010-07-01 20:58:00 +00:00
|
|
|
DNPRINTF(SWM_D_STACK, "horizontal_stack: workspace: %d\n", ws->idx);
|
2009-01-15 13:59:58 +00:00
|
|
|
|
2012-02-08 01:17:20 +08:00
|
|
|
stack_master(ws, g, 1, ws->l_state.horizontal_flip);
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 10:02:13 +00:00
|
|
|
/* fullscreen view */
|
2009-01-15 13:59:58 +00:00
|
|
|
void
|
2009-09-23 03:34:58 +00:00
|
|
|
max_stack(struct workspace *ws, struct swm_geometry *g)
|
|
|
|
{
|
2009-01-15 13:59:58 +00:00
|
|
|
XWindowChanges wc;
|
2009-01-16 05:25:13 +00:00
|
|
|
struct swm_geometry gg = *g;
|
2009-10-15 22:18:45 +00:00
|
|
|
struct ws_win *win, *wintrans = NULL, *parent = NULL;
|
2009-01-17 14:17:09 +00:00
|
|
|
unsigned int mask;
|
2009-09-23 03:34:58 +00:00
|
|
|
int winno;
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
DNPRINTF(SWM_D_STACK, "max_stack: workspace: %d\n", ws->idx);
|
2009-01-15 13:59:58 +00:00
|
|
|
|
2009-10-02 15:40:43 +00:00
|
|
|
if (ws == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-09-23 03:34:58 +00:00
|
|
|
winno = count_win(ws, 0);
|
|
|
|
if (winno == 0 && count_win(ws, 1) == 0)
|
2009-01-15 13:59:58 +00:00
|
|
|
return;
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(win, &ws->winlist, entry) {
|
2009-10-12 04:09:17 +00:00
|
|
|
if (win->transient) {
|
2009-10-01 15:17:17 +00:00
|
|
|
wintrans = win;
|
2009-10-15 22:18:45 +00:00
|
|
|
parent = find_window(win->transient);
|
2009-10-12 04:09:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
if (win->floating && win->floatmaxed == 0 ) {
|
|
|
|
/*
|
|
|
|
* retain geometry for retrieval on exit from
|
|
|
|
* max_stack mode
|
|
|
|
*/
|
|
|
|
store_float_geom(win, ws->r);
|
|
|
|
win->floatmaxed = 1;
|
|
|
|
}
|
|
|
|
|
2009-10-12 04:09:17 +00:00
|
|
|
/* only reconfigure if necessary */
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) != gg.x || Y(win) != gg.y || WIDTH(win) != gg.w ||
|
|
|
|
HEIGHT(win) != gg.h) {
|
2009-01-15 13:59:58 +00:00
|
|
|
bzero(&wc, sizeof wc);
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = wc.x = gg.x;
|
|
|
|
Y(win) = wc.y = gg.y;
|
2010-07-01 21:13:02 +00:00
|
|
|
if (bar_enabled){
|
2011-03-11 14:12:49 +00:00
|
|
|
wc.border_width = border_width;
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = wc.width = gg.w;
|
|
|
|
HEIGHT(win) = wc.height = gg.h;
|
2010-07-01 21:13:02 +00:00
|
|
|
} else {
|
|
|
|
wc.border_width = 0;
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = wc.width = gg.w + 2 * border_width;
|
|
|
|
HEIGHT(win) = wc.height = gg.h +
|
|
|
|
2 * border_width;
|
2010-07-01 21:13:02 +00:00
|
|
|
}
|
2009-01-15 13:59:58 +00:00
|
|
|
mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
|
|
|
|
XConfigureWindow(display, win->id, mask, &wc);
|
|
|
|
}
|
2009-10-12 04:09:17 +00:00
|
|
|
/* unmap only if we don't have multi screen */
|
|
|
|
if (win != ws->focus)
|
|
|
|
if (!(ScreenCount(display) > 1 || outputs > 1))
|
|
|
|
unmap_window(win);
|
2009-01-15 13:59:58 +00:00
|
|
|
}
|
2009-10-01 15:17:17 +00:00
|
|
|
|
|
|
|
/* put the last transient on top */
|
|
|
|
if (wintrans) {
|
2009-10-15 22:18:45 +00:00
|
|
|
if (parent)
|
|
|
|
XMapRaised(display, parent->id);
|
2009-10-01 15:17:17 +00:00
|
|
|
stack_floater(wintrans, ws->r);
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(wintrans);
|
2009-10-01 15:17:17 +00:00
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 05:48:18 +00:00
|
|
|
void
|
2009-01-19 09:05:02 +00:00
|
|
|
send_to_ws(struct swm_region *r, union arg *args)
|
2009-01-14 05:48:18 +00:00
|
|
|
{
|
|
|
|
int wsid = args->id;
|
2011-06-08 22:36:44 +00:00
|
|
|
struct ws_win *win = NULL, *parent;
|
2009-01-19 05:48:11 +00:00
|
|
|
struct workspace *ws, *nws;
|
2009-01-23 01:01:48 +00:00
|
|
|
Atom ws_idx_atom = 0;
|
2009-01-24 17:57:26 +00:00
|
|
|
unsigned char ws_idx_str[SWM_PROPLEN];
|
2009-10-15 20:42:59 +00:00
|
|
|
union arg a;
|
2009-01-14 05:48:18 +00:00
|
|
|
|
2012-04-08 01:59:41 +08:00
|
|
|
if (wsid >= workspace_limit)
|
|
|
|
return;
|
|
|
|
|
2012-01-09 20:30:00 -05:00
|
|
|
if (r && r->ws && r->ws->focus)
|
2009-10-02 06:18:41 +00:00
|
|
|
win = r->ws->focus;
|
|
|
|
else
|
|
|
|
return;
|
2009-01-30 03:51:01 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
2009-10-20 22:42:35 +00:00
|
|
|
if (win->ws->idx == wsid)
|
|
|
|
return;
|
2009-01-30 03:51:01 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MOVE, "send_to_ws: window: 0x%lx\n", win->id);
|
2009-01-14 05:48:18 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
ws = win->ws;
|
|
|
|
nws = &win->s->ws[wsid];
|
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
a.id = SWM_ARG_ID_FOCUSPREV;
|
|
|
|
focus(r, &a);
|
2011-06-08 22:36:44 +00:00
|
|
|
if (win->transient) {
|
|
|
|
parent = find_window(win->transient);
|
|
|
|
if (parent) {
|
|
|
|
unmap_window(parent);
|
|
|
|
TAILQ_REMOVE(&ws->winlist, parent, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&nws->winlist, parent, entry);
|
|
|
|
parent->ws = nws;
|
|
|
|
}
|
|
|
|
}
|
2009-10-02 06:18:41 +00:00
|
|
|
unmap_window(win);
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_REMOVE(&ws->winlist, win, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&nws->winlist, win, entry);
|
2012-01-09 20:30:00 -05:00
|
|
|
if (TAILQ_EMPTY(&ws->winlist))
|
|
|
|
r->ws->focus = NULL;
|
2009-01-19 05:48:11 +00:00
|
|
|
win->ws = nws;
|
2009-01-14 05:48:18 +00:00
|
|
|
|
2009-01-23 01:01:48 +00:00
|
|
|
/* Try to update the window's workspace property */
|
|
|
|
ws_idx_atom = XInternAtom(display, "_SWM_WS", False);
|
2009-01-24 17:57:26 +00:00
|
|
|
if (ws_idx_atom &&
|
2011-09-19 21:56:45 -05:00
|
|
|
snprintf((char *)ws_idx_str, SWM_PROPLEN, "%d", nws->idx) <
|
|
|
|
SWM_PROPLEN) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_PROP, "send_to_ws: set property: _SWM_WS: %s\n",
|
2009-01-24 17:57:26 +00:00
|
|
|
ws_idx_str);
|
|
|
|
XChangeProperty(display, win->id, ws_idx_atom, XA_STRING, 8,
|
2012-02-13 23:32:31 +08:00
|
|
|
PropModeReplace, ws_idx_str, strlen((char *)ws_idx_str));
|
2009-01-24 17:57:26 +00:00
|
|
|
}
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2009-01-14 05:48:18 +00:00
|
|
|
stack();
|
2012-05-12 22:49:42 +01:00
|
|
|
bar_update();
|
2009-01-14 05:48:18 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 22:41:51 +00:00
|
|
|
void
|
|
|
|
pressbutton(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
XTestFakeButtonEvent(display, args->id, True, CurrentTime);
|
|
|
|
XTestFakeButtonEvent(display, args->id, False, CurrentTime);
|
|
|
|
}
|
|
|
|
|
2011-06-24 16:53:40 +00:00
|
|
|
void
|
|
|
|
raise_toggle(struct swm_region *r, union arg *args)
|
|
|
|
{
|
2012-02-17 10:27:40 -06:00
|
|
|
if (r == NULL || r->ws == NULL)
|
2011-06-24 16:53:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
r->ws->always_raise = !r->ws->always_raise;
|
|
|
|
|
|
|
|
/* bring floaters back to top */
|
|
|
|
if (r->ws->always_raise == 0)
|
|
|
|
stack();
|
|
|
|
}
|
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
void
|
|
|
|
iconify(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
union arg a;
|
|
|
|
|
|
|
|
if (r->ws->focus == NULL)
|
|
|
|
return;
|
|
|
|
unmap_window(r->ws->focus);
|
|
|
|
update_iconic(r->ws->focus, 1);
|
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2011-06-06 19:52:03 +00:00
|
|
|
r->ws->focus = NULL;
|
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(r, &a);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char *
|
2012-02-04 14:25:40 +00:00
|
|
|
get_win_name(Window win)
|
2011-06-06 19:52:03 +00:00
|
|
|
{
|
|
|
|
unsigned char *prop = NULL;
|
2012-02-04 14:41:30 +00:00
|
|
|
unsigned long nbytes, nitems;
|
2011-06-06 19:52:03 +00:00
|
|
|
|
2012-02-04 14:41:30 +00:00
|
|
|
/* try _NET_WM_NAME first */
|
|
|
|
if (get_property(win, a_netwmname, 0L, a_utf8_string, NULL, &nbytes,
|
|
|
|
&prop)) {
|
2012-02-07 22:57:16 +00:00
|
|
|
XFree(prop);
|
2012-02-04 14:41:30 +00:00
|
|
|
if (get_property(win, a_netwmname, nbytes, a_utf8_string,
|
|
|
|
&nitems, NULL, &prop))
|
|
|
|
return (prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fallback to WM_NAME */
|
|
|
|
if (!get_property(win, a_wmname, 0L, a_string, NULL, &nbytes, &prop))
|
2012-02-07 22:57:16 +00:00
|
|
|
return (NULL);
|
2011-06-06 19:52:03 +00:00
|
|
|
XFree(prop);
|
2012-02-04 14:41:30 +00:00
|
|
|
if (get_property(win, a_wmname, nbytes, a_string, &nitems, NULL, &prop))
|
|
|
|
return (prop);
|
2011-06-06 19:52:03 +00:00
|
|
|
|
2012-02-04 14:41:30 +00:00
|
|
|
return (NULL);
|
2011-06-06 19:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uniconify(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
FILE *lfile;
|
2011-09-19 21:56:45 -05:00
|
|
|
unsigned char *name;
|
2011-06-06 19:52:03 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "uniconify\n");
|
|
|
|
|
2012-02-17 10:27:40 -06:00
|
|
|
if (r == NULL || r->ws == NULL)
|
2011-06-06 19:52:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* make sure we have anything to uniconify */
|
|
|
|
TAILQ_FOREACH(win, &r->ws->winlist, entry) {
|
|
|
|
if (win->ws == NULL)
|
|
|
|
continue; /* should never happen */
|
|
|
|
if (win->iconic == 0)
|
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
search_r = r;
|
2011-11-28 23:15:28 -05:00
|
|
|
search_resp_action = SWM_SEARCH_UNICONIFY;
|
2011-06-06 19:52:03 +00:00
|
|
|
|
2011-11-28 23:15:28 -05:00
|
|
|
spawn_select(r, args, "search", &searchpid);
|
2011-06-06 19:52:03 +00:00
|
|
|
|
|
|
|
if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(win, &r->ws->winlist, entry) {
|
|
|
|
if (win->ws == NULL)
|
|
|
|
continue; /* should never happen */
|
|
|
|
if (win->iconic == 0)
|
|
|
|
continue;
|
|
|
|
|
2012-02-04 14:25:40 +00:00
|
|
|
name = get_win_name(win->id);
|
2011-06-06 19:52:03 +00:00
|
|
|
if (name == NULL)
|
|
|
|
continue;
|
|
|
|
fprintf(lfile, "%s.%lu\n", name, win->id);
|
|
|
|
XFree(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(lfile);
|
|
|
|
}
|
|
|
|
|
2011-11-28 23:25:46 -05:00
|
|
|
void
|
|
|
|
name_workspace(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
FILE *lfile;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "name_workspace\n");
|
|
|
|
|
2011-12-03 22:35:59 -05:00
|
|
|
if (r == NULL)
|
2011-11-28 23:25:46 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
search_r = r;
|
|
|
|
search_resp_action = SWM_SEARCH_NAME_WORKSPACE;
|
|
|
|
|
|
|
|
spawn_select(r, args, "name_workspace", &searchpid);
|
|
|
|
|
|
|
|
if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(lfile, "%s", "");
|
|
|
|
fclose(lfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
search_workspace(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct workspace *ws;
|
|
|
|
FILE *lfile;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "search_workspace\n");
|
|
|
|
|
|
|
|
if (r == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
search_r = r;
|
|
|
|
search_resp_action = SWM_SEARCH_SEARCH_WORKSPACE;
|
|
|
|
|
|
|
|
spawn_select(r, args, "search", &searchpid);
|
|
|
|
|
|
|
|
if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-04-08 01:59:41 +08:00
|
|
|
for (i = 0; i < workspace_limit; i++) {
|
2011-11-28 23:25:46 -05:00
|
|
|
ws = &r->s->ws[i];
|
|
|
|
if (ws == NULL)
|
|
|
|
continue;
|
|
|
|
fprintf(lfile, "%d%s%s\n", ws->idx + 1,
|
|
|
|
(ws->name ? ":" : ""), (ws->name ? ws->name : ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(lfile);
|
|
|
|
}
|
|
|
|
|
2011-11-28 23:41:37 -05:00
|
|
|
void
|
|
|
|
search_win_cleanup(void)
|
|
|
|
{
|
|
|
|
struct search_window *sw = NULL;
|
|
|
|
|
|
|
|
while ((sw = TAILQ_FIRST(&search_wl)) != NULL) {
|
|
|
|
XDestroyWindow(display, sw->indicator);
|
2012-02-02 07:00:45 +08:00
|
|
|
XFreeGC(display, sw->gc);
|
2011-11-28 23:41:37 -05:00
|
|
|
TAILQ_REMOVE(&search_wl, sw, entry);
|
|
|
|
free(sw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
search_win(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win = NULL;
|
|
|
|
struct search_window *sw = NULL;
|
|
|
|
Window w;
|
|
|
|
XGCValues gcv;
|
|
|
|
int i;
|
|
|
|
char s[8];
|
|
|
|
FILE *lfile;
|
|
|
|
size_t len;
|
2012-02-02 07:00:45 +08:00
|
|
|
XRectangle ibox, lbox;
|
2011-11-28 23:41:37 -05:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "search_win\n");
|
|
|
|
|
|
|
|
search_r = r;
|
|
|
|
search_resp_action = SWM_SEARCH_SEARCH_WINDOW;
|
|
|
|
|
|
|
|
spawn_select(r, args, "search", &searchpid);
|
|
|
|
|
|
|
|
if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAILQ_INIT(&search_wl);
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
TAILQ_FOREACH(win, &r->ws->winlist, entry) {
|
|
|
|
if (win->iconic == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sw = calloc(1, sizeof(struct search_window));
|
|
|
|
if (sw == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("search_win: calloc");
|
2011-11-28 23:41:37 -05:00
|
|
|
fclose(lfile);
|
|
|
|
search_win_cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sw->idx = i;
|
|
|
|
sw->win = win;
|
|
|
|
|
|
|
|
snprintf(s, sizeof s, "%d", i);
|
|
|
|
len = strlen(s);
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
XmbTextExtents(bar_fs, s, len, &ibox, &lbox);
|
2011-11-28 23:41:37 -05:00
|
|
|
|
|
|
|
w = XCreateSimpleWindow(display,
|
2012-02-02 07:00:45 +08:00
|
|
|
win->id, 0, 0,lbox.width + 4,
|
|
|
|
bar_fs_extents->max_logical_extent.height, 1,
|
2011-11-28 23:41:37 -05:00
|
|
|
r->s->c[SWM_S_COLOR_UNFOCUS].color,
|
|
|
|
r->s->c[SWM_S_COLOR_FOCUS].color);
|
|
|
|
|
|
|
|
sw->indicator = w;
|
|
|
|
TAILQ_INSERT_TAIL(&search_wl, sw, entry);
|
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
sw->gc = XCreateGC(display, w, 0, &gcv);
|
2011-11-28 23:41:37 -05:00
|
|
|
XMapRaised(display, w);
|
2012-02-02 07:00:45 +08:00
|
|
|
XSetForeground(display, sw->gc, r->s->c[SWM_S_COLOR_BAR].color);
|
2011-11-28 23:41:37 -05:00
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
DRAWSTRING(display, w, bar_fs, sw->gc, 2,
|
|
|
|
(bar_fs_extents->max_logical_extent.height -
|
|
|
|
lbox.height) / 2 - lbox.y, s, len);
|
2011-11-28 23:41:37 -05:00
|
|
|
|
|
|
|
fprintf(lfile, "%d\n", i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(lfile);
|
|
|
|
}
|
|
|
|
|
2011-11-28 23:15:28 -05:00
|
|
|
void
|
|
|
|
search_resp_uniconify(char *resp, unsigned long len)
|
|
|
|
{
|
|
|
|
unsigned char *name;
|
|
|
|
struct ws_win *win;
|
|
|
|
char *s;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_uniconify: resp: %s\n", resp);
|
2011-11-28 23:15:28 -05:00
|
|
|
|
|
|
|
TAILQ_FOREACH(win, &search_r->ws->winlist, entry) {
|
|
|
|
if (win->iconic == 0)
|
|
|
|
continue;
|
2012-02-04 14:25:40 +00:00
|
|
|
name = get_win_name(win->id);
|
2011-11-28 23:15:28 -05:00
|
|
|
if (name == NULL)
|
|
|
|
continue;
|
|
|
|
if (asprintf(&s, "%s.%lu", name, win->id) == -1) {
|
|
|
|
XFree(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
XFree(name);
|
|
|
|
if (strncmp(s, resp, len) == 0) {
|
|
|
|
/* XXX this should be a callback to generalize */
|
|
|
|
update_iconic(win, 0);
|
|
|
|
free(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 23:25:46 -05:00
|
|
|
void
|
|
|
|
search_resp_name_workspace(char *resp, unsigned long len)
|
|
|
|
{
|
|
|
|
struct workspace *ws;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_name_workspace: resp: %s\n", resp);
|
2011-11-28 23:25:46 -05:00
|
|
|
|
|
|
|
if (search_r->ws == NULL)
|
|
|
|
return;
|
|
|
|
ws = search_r->ws;
|
|
|
|
|
|
|
|
if (ws->name) {
|
|
|
|
free(search_r->ws->name);
|
|
|
|
search_r->ws->name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 1) {
|
|
|
|
ws->name = strdup(resp);
|
|
|
|
if (ws->name == NULL) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_name_workspace: "
|
|
|
|
"strdup: %s", strerror(errno));
|
2011-11-28 23:25:46 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
search_resp_search_workspace(char *resp, unsigned long len)
|
|
|
|
{
|
|
|
|
char *p, *q;
|
|
|
|
int ws_idx;
|
|
|
|
const char *errstr;
|
|
|
|
union arg a;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: resp: %s\n", resp);
|
2011-11-28 23:25:46 -05:00
|
|
|
|
|
|
|
q = strdup(resp);
|
|
|
|
if (!q) {
|
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: strdup: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = strchr(q, ':');
|
|
|
|
if (p != NULL)
|
|
|
|
*p = '\0';
|
2012-04-08 01:59:41 +08:00
|
|
|
ws_idx = strtonum(q, 1, workspace_limit, &errstr);
|
2011-11-28 23:25:46 -05:00
|
|
|
if (errstr) {
|
|
|
|
DNPRINTF(SWM_D_MISC, "workspace idx is %s: %s",
|
|
|
|
errstr, q);
|
|
|
|
free(q);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(q);
|
|
|
|
a.id = ws_idx - 1;
|
|
|
|
switchws(search_r, &a);
|
|
|
|
}
|
|
|
|
|
2011-11-28 23:41:37 -05:00
|
|
|
void
|
|
|
|
search_resp_search_window(char *resp, unsigned long len)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int idx;
|
|
|
|
const char *errstr;
|
|
|
|
struct search_window *sw;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_search_window: resp: %s\n", resp);
|
2011-11-28 23:41:37 -05:00
|
|
|
|
|
|
|
s = strdup(resp);
|
|
|
|
if (!s) {
|
|
|
|
DNPRINTF(SWM_D_MISC, "search_resp_search_window: strdup: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2011-11-29 23:39:31 +00:00
|
|
|
|
2011-11-28 23:41:37 -05:00
|
|
|
idx = strtonum(s, 1, INT_MAX, &errstr);
|
|
|
|
if (errstr) {
|
|
|
|
DNPRINTF(SWM_D_MISC, "window idx is %s: %s",
|
|
|
|
errstr, s);
|
|
|
|
free(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(sw, &search_wl, entry)
|
|
|
|
if (idx == sw->idx) {
|
|
|
|
focus_win(sw->win);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
#define MAX_RESP_LEN 1024
|
|
|
|
|
|
|
|
void
|
|
|
|
search_do_resp(void)
|
|
|
|
{
|
|
|
|
ssize_t rbytes;
|
2011-11-28 23:15:28 -05:00
|
|
|
char *resp;
|
2011-06-06 19:52:03 +00:00
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "search_do_resp:\n");
|
|
|
|
|
|
|
|
search_resp = 0;
|
|
|
|
searchpid = 0;
|
|
|
|
|
|
|
|
if ((resp = calloc(1, MAX_RESP_LEN + 1)) == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("search: calloc");
|
2011-11-17 19:05:31 -05:00
|
|
|
goto done;
|
2011-06-06 19:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rbytes = read(select_resp_pipe[0], resp, MAX_RESP_LEN);
|
|
|
|
if (rbytes <= 0) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warn("search: read error");
|
2011-06-06 19:52:03 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
resp[rbytes] = '\0';
|
2011-11-29 23:39:31 +00:00
|
|
|
|
|
|
|
/* XXX:
|
|
|
|
* Older versions of dmenu (Atleast pre 4.4.1) do not send a
|
|
|
|
* newline, so work around that by sanitizing the resp now.
|
|
|
|
*/
|
|
|
|
resp[strcspn(resp, "\n")] = '\0';
|
2011-06-06 19:52:03 +00:00
|
|
|
len = strlen(resp);
|
|
|
|
|
2011-11-28 23:15:28 -05:00
|
|
|
switch (search_resp_action) {
|
|
|
|
case SWM_SEARCH_UNICONIFY:
|
|
|
|
search_resp_uniconify(resp, len);
|
|
|
|
break;
|
2011-11-28 23:25:46 -05:00
|
|
|
case SWM_SEARCH_NAME_WORKSPACE:
|
|
|
|
search_resp_name_workspace(resp, len);
|
|
|
|
break;
|
|
|
|
case SWM_SEARCH_SEARCH_WORKSPACE:
|
|
|
|
search_resp_search_workspace(resp, len);
|
|
|
|
break;
|
2011-11-28 23:41:37 -05:00
|
|
|
case SWM_SEARCH_SEARCH_WINDOW:
|
|
|
|
search_resp_search_window(resp, len);
|
|
|
|
break;
|
2011-06-06 19:52:03 +00:00
|
|
|
}
|
2011-11-28 23:15:28 -05:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
done:
|
2011-11-28 23:41:37 -05:00
|
|
|
if (search_resp_action == SWM_SEARCH_SEARCH_WINDOW)
|
|
|
|
search_win_cleanup();
|
|
|
|
|
2011-11-28 23:15:28 -05:00
|
|
|
search_resp_action = SWM_SEARCH_NONE;
|
2011-11-17 19:05:31 -05:00
|
|
|
close(select_resp_pipe[0]);
|
2011-06-06 19:52:03 +00:00
|
|
|
free(resp);
|
|
|
|
}
|
|
|
|
|
2009-01-22 18:11:52 +00:00
|
|
|
void
|
|
|
|
wkill(struct swm_region *r, union arg *args)
|
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "wkill: id: %d\n", args->id);
|
2009-02-10 18:16:10 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
if (r->ws->focus == NULL)
|
2009-02-10 18:16:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (args->id == SWM_ARG_ID_KILLWINDOW)
|
2009-01-22 18:11:52 +00:00
|
|
|
XKillClient(display, r->ws->focus->id);
|
2009-02-10 18:16:10 +00:00
|
|
|
else
|
|
|
|
if (r->ws->focus->can_delete)
|
|
|
|
client_msg(r->ws->focus, adelete);
|
2009-01-22 18:11:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
floating_toggle_win(struct ws_win *win)
|
2009-02-01 01:39:25 +00:00
|
|
|
{
|
2010-09-16 02:26:45 +00:00
|
|
|
struct swm_region *r;
|
2009-02-01 01:39:25 +00:00
|
|
|
|
|
|
|
if (win == NULL)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (0);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (!win->ws->r)
|
2012-05-12 21:28:49 +01:00
|
|
|
return (0);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
r = win->ws->r;
|
2009-02-01 01:39:25 +00:00
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
/* reject floating toggles in max stack mode */
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->ws->cur_layout == &layouts[SWM_MAX_STACK])
|
2012-05-12 21:28:49 +01:00
|
|
|
return (0);
|
2010-07-01 20:58:00 +00:00
|
|
|
|
|
|
|
if (win->floating) {
|
|
|
|
if (!win->floatmaxed) {
|
|
|
|
/* retain position for refloat */
|
|
|
|
store_float_geom(win, r);
|
|
|
|
}
|
|
|
|
win->floating = 0;
|
|
|
|
} else {
|
|
|
|
if (win->g_floatvalid) {
|
2010-09-16 02:26:45 +00:00
|
|
|
/* refloat at last floating relative position */
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = win->g_float.x - win->rg_float.x + X(r);
|
|
|
|
Y(win) = win->g_float.y - win->rg_float.y + Y(r);
|
|
|
|
WIDTH(win) = win->g_float.w;
|
|
|
|
HEIGHT(win) = win->g_float.h;
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
2010-07-01 20:58:00 +00:00
|
|
|
win->floating = 1;
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_actions(win);
|
|
|
|
|
2012-05-12 21:28:49 +01:00
|
|
|
return (1);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
floating_toggle(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win = r->ws->focus;
|
|
|
|
union arg a;
|
|
|
|
|
2011-01-18 19:18:31 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_win_state(win, ewmh[_NET_WM_STATE_ABOVE].atom,
|
|
|
|
_NET_WM_STATE_TOGGLE);
|
|
|
|
|
2009-02-01 01:39:25 +00:00
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
if (win == win->ws->focus) {
|
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(win->ws->r, &a);
|
|
|
|
}
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 03:46:13 +00:00
|
|
|
void
|
2012-01-22 03:38:04 +08:00
|
|
|
constrain_window(struct ws_win *win, struct swm_region *r, int resizable)
|
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) + WIDTH(win) > X(r) + WIDTH(r) - border_width) {
|
2012-01-22 09:44:40 -06:00
|
|
|
if (resizable)
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = X(r) + WIDTH(r) - X(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
else
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = X(r) + WIDTH(r) - WIDTH(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
2012-01-22 09:44:40 -06:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (X(win) < X(r) - border_width) {
|
2012-01-22 03:38:04 +08:00
|
|
|
if (resizable)
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) -= X(r) - X(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = X(r) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (Y(win) + HEIGHT(win) > Y(r) + HEIGHT(r) - border_width) {
|
2012-01-22 03:38:04 +08:00
|
|
|
if (resizable)
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) = Y(r) + HEIGHT(r) - Y(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
else
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) = Y(r) + HEIGHT(r) - HEIGHT(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
2012-01-22 09:44:40 -06:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (Y(win) < Y(r) - border_width) {
|
2012-01-22 03:38:04 +08:00
|
|
|
if (resizable)
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) -= Y(r) - Y(win) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) = Y(r) - border_width;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (WIDTH(win) < 1)
|
|
|
|
WIDTH(win) = 1;
|
|
|
|
if (HEIGHT(win) < 1)
|
|
|
|
HEIGHT(win) = 1;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
update_window(struct ws_win *win)
|
2009-01-29 21:38:49 +00:00
|
|
|
{
|
|
|
|
unsigned int mask;
|
|
|
|
XWindowChanges wc;
|
|
|
|
|
|
|
|
bzero(&wc, sizeof wc);
|
2012-01-22 03:38:04 +08:00
|
|
|
mask = CWBorderWidth | CWWidth | CWHeight | CWX | CWY;
|
2011-03-11 14:12:49 +00:00
|
|
|
wc.border_width = border_width;
|
2012-01-29 01:29:31 +08:00
|
|
|
wc.x = X(win);
|
|
|
|
wc.y = Y(win);
|
|
|
|
wc.width = WIDTH(win);
|
|
|
|
wc.height = HEIGHT(win);
|
2009-01-29 21:38:49 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "update_window: window: 0x%lx, (x,y) w x h: "
|
|
|
|
"(%d,%d) %d x %d\n", win->id, wc.x, wc.y, wc.width, wc.height);
|
2009-01-29 21:38:49 +00:00
|
|
|
|
|
|
|
XConfigureWindow(display, win->id, mask, &wc);
|
|
|
|
}
|
|
|
|
|
2011-10-03 16:39:12 -05:00
|
|
|
#define SWM_RESIZE_STEPS (50)
|
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
void
|
2009-01-29 22:15:15 +00:00
|
|
|
resize(struct ws_win *win, union arg *args)
|
2009-01-29 21:38:49 +00:00
|
|
|
{
|
|
|
|
XEvent ev;
|
2009-02-01 01:39:25 +00:00
|
|
|
Time time = 0;
|
2011-10-19 21:50:02 -04:00
|
|
|
struct swm_region *r = NULL;
|
2011-10-03 16:39:12 -05:00
|
|
|
int resize_step = 0;
|
2012-01-22 03:38:04 +08:00
|
|
|
Window rr, cr;
|
|
|
|
int x, y, wx, wy;
|
|
|
|
unsigned int mask;
|
|
|
|
struct swm_geometry g;
|
|
|
|
int top = 0, left = 0;
|
2012-01-22 09:44:40 -06:00
|
|
|
int dx, dy;
|
2012-01-22 03:38:04 +08:00
|
|
|
Cursor cursor;
|
|
|
|
unsigned int shape; /* cursor style */
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2011-10-19 21:50:02 -04:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
r = win->ws->r;
|
2009-01-29 21:38:49 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MOUSE, "resize: window: 0x%lx, floating: %s, "
|
|
|
|
"transient: 0x%lx\n", win->id, YESNO(win->floating),
|
|
|
|
win->transient);
|
2009-01-29 21:38:49 +00:00
|
|
|
|
|
|
|
if (!(win->transient != 0 || win->floating != 0))
|
|
|
|
return;
|
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
/* reject resizes in max mode for floaters (transient ok) */
|
|
|
|
if (win->floatmaxed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
win->manual = 1;
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_win_state(win, ewmh[_SWM_WM_STATE_MANUAL].atom,
|
|
|
|
_NET_WM_STATE_ADD);
|
2011-06-14 15:28:05 +00:00
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
stack();
|
2011-10-03 16:39:12 -05:00
|
|
|
|
|
|
|
switch (args->id) {
|
|
|
|
case SWM_ARG_ID_WIDTHSHRINK:
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) -= SWM_RESIZE_STEPS;
|
2011-10-03 16:39:12 -05:00
|
|
|
resize_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_WIDTHGROW:
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) += SWM_RESIZE_STEPS;
|
2011-10-03 16:39:12 -05:00
|
|
|
resize_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_HEIGHTSHRINK:
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) -= SWM_RESIZE_STEPS;
|
2011-10-03 16:39:12 -05:00
|
|
|
resize_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_HEIGHTGROW:
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) += SWM_RESIZE_STEPS;
|
2011-10-03 16:39:12 -05:00
|
|
|
resize_step = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (resize_step) {
|
2012-01-22 03:38:04 +08:00
|
|
|
constrain_window(win, r, 1);
|
|
|
|
update_window(win);
|
2011-10-03 16:39:12 -05:00
|
|
|
store_float_geom(win,r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2012-01-22 03:38:04 +08:00
|
|
|
/* get cursor offset from window root */
|
|
|
|
if (!XQueryPointer(display, win->id, &rr, &cr, &x, &y, &wx, &wy, &mask))
|
|
|
|
return;
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2012-01-22 03:38:04 +08:00
|
|
|
g = win->g;
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (wx < WIDTH(win) / 2)
|
2012-01-22 03:38:04 +08:00
|
|
|
left = 1;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
if (wy < HEIGHT(win) / 2)
|
2012-01-22 03:38:04 +08:00
|
|
|
top = 1;
|
|
|
|
|
|
|
|
if (args->id == SWM_ARG_ID_CENTER)
|
|
|
|
shape = XC_sizing;
|
|
|
|
else if (top)
|
|
|
|
shape = (left) ? XC_top_left_corner : XC_top_right_corner;
|
2012-01-22 09:44:40 -06:00
|
|
|
else
|
2012-01-22 03:38:04 +08:00
|
|
|
shape = (left) ? XC_bottom_left_corner : XC_bottom_right_corner;
|
|
|
|
|
|
|
|
cursor = XCreateFontCursor(display, shape);
|
|
|
|
|
|
|
|
if (XGrabPointer(display, win->id, False, MOUSEMASK, GrabModeAsync,
|
|
|
|
GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) {
|
2012-01-22 09:44:40 -06:00
|
|
|
XFreeCursor(display, cursor);
|
2012-01-22 03:38:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-07-01 20:58:00 +00:00
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
do {
|
|
|
|
XMaskEvent(display, MOUSEMASK | ExposureMask |
|
|
|
|
SubstructureRedirectMask, &ev);
|
2011-06-14 22:20:55 +00:00
|
|
|
switch (ev.type) {
|
2009-01-29 21:38:49 +00:00
|
|
|
case ConfigureRequest:
|
|
|
|
case Expose:
|
|
|
|
case MapRequest:
|
|
|
|
handler[ev.type](&ev);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2012-01-22 03:38:04 +08:00
|
|
|
/* cursor offset/delta from start of the operation */
|
|
|
|
dx = ev.xmotion.x_root - x;
|
|
|
|
dy = ev.xmotion.y_root - y;
|
2009-10-13 17:22:42 +00:00
|
|
|
|
2012-01-22 03:38:04 +08:00
|
|
|
/* vertical */
|
|
|
|
if (top)
|
|
|
|
dy = -dy;
|
|
|
|
|
|
|
|
if (args->id == SWM_ARG_ID_CENTER) {
|
|
|
|
if (g.h / 2 + dy < 1)
|
|
|
|
dy = 1 - g.h / 2;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) = g.y - dy;
|
|
|
|
HEIGHT(win) = g.h + 2 * dy;
|
2012-01-22 03:38:04 +08:00
|
|
|
} else {
|
|
|
|
if (g.h + dy < 1)
|
|
|
|
dy = 1 - g.h;
|
|
|
|
|
|
|
|
if (top)
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) = g.y - dy;
|
2012-01-22 03:38:04 +08:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) = g.h + dy;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* horizontal */
|
2012-02-11 09:45:09 +08:00
|
|
|
if (left)
|
2012-01-22 03:38:04 +08:00
|
|
|
dx = -dx;
|
|
|
|
|
|
|
|
if (args->id == SWM_ARG_ID_CENTER) {
|
|
|
|
if (g.w / 2 + dx < 1)
|
|
|
|
dx = 1 - g.w / 2;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = g.x - dx;
|
|
|
|
WIDTH(win) = g.w + 2 * dx;
|
2012-01-22 03:38:04 +08:00
|
|
|
} else {
|
|
|
|
if (g.w + dx < 1)
|
|
|
|
dx = 1 - g.w;
|
|
|
|
|
|
|
|
if (left)
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = g.x - dx;
|
2012-01-22 03:38:04 +08:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = g.w + dx;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constrain_window(win, r, 1);
|
2009-02-01 01:39:25 +00:00
|
|
|
|
2011-03-11 14:12:49 +00:00
|
|
|
/* not free, don't sync more than 120 times / second */
|
|
|
|
if ((ev.xmotion.time - time) > (1000 / 120) ) {
|
2009-02-01 01:39:25 +00:00
|
|
|
time = ev.xmotion.time;
|
|
|
|
XSync(display, False);
|
2012-01-22 03:38:04 +08:00
|
|
|
update_window(win);
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
2009-01-29 21:38:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (ev.type != ButtonRelease);
|
2009-02-01 01:39:25 +00:00
|
|
|
if (time) {
|
|
|
|
XSync(display, False);
|
2012-01-22 03:38:04 +08:00
|
|
|
update_window(win);
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
2010-07-01 20:58:00 +00:00
|
|
|
store_float_geom(win,r);
|
|
|
|
|
2009-01-29 21:38:49 +00:00
|
|
|
XUngrabPointer(display, CurrentTime);
|
2012-01-22 03:38:04 +08:00
|
|
|
XFreeCursor(display, cursor);
|
2009-01-29 21:38:49 +00:00
|
|
|
|
|
|
|
/* drain events */
|
2011-06-09 21:15:29 +00:00
|
|
|
drain_enter_notify();
|
2009-01-29 21:38:49 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 16:39:12 -05:00
|
|
|
void
|
|
|
|
resize_step(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win = NULL;
|
|
|
|
|
2011-10-19 21:50:02 -04:00
|
|
|
if (r && r->ws && r->ws->focus)
|
2011-10-03 16:39:12 -05:00
|
|
|
win = r->ws->focus;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
resize(win, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SWM_MOVE_STEPS (50)
|
|
|
|
|
2009-01-29 22:15:15 +00:00
|
|
|
void
|
|
|
|
move(struct ws_win *win, union arg *args)
|
|
|
|
{
|
|
|
|
XEvent ev;
|
2009-02-01 01:39:25 +00:00
|
|
|
Time time = 0;
|
2011-10-03 16:39:12 -05:00
|
|
|
int move_step = 0;
|
2011-10-19 21:50:02 -04:00
|
|
|
struct swm_region *r = NULL;
|
|
|
|
|
2012-01-22 03:38:04 +08:00
|
|
|
Window rr, cr;
|
|
|
|
int x, y, wx, wy;
|
|
|
|
unsigned int mask;
|
|
|
|
|
2011-10-19 21:50:02 -04:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
r = win->ws->r;
|
2009-01-29 22:15:15 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MOUSE, "move: window: 0x%lx, floating: %s, transient: "
|
|
|
|
"0x%lx\n", win->id, YESNO(win->floating), win->transient);
|
2009-01-29 22:15:15 +00:00
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
/* in max_stack mode should only move transients */
|
|
|
|
if (win->ws->cur_layout == &layouts[SWM_MAX_STACK] && !win->transient)
|
|
|
|
return;
|
|
|
|
|
|
|
|
win->manual = 1;
|
|
|
|
if (win->floating == 0 && !win->transient) {
|
2012-01-26 00:37:03 +08:00
|
|
|
store_float_geom(win,r);
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_win_state(win, ewmh[_NET_WM_STATE_ABOVE].atom,
|
|
|
|
_NET_WM_STATE_ADD);
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_win_state(win, ewmh[_SWM_WM_STATE_MANUAL].atom,
|
|
|
|
_NET_WM_STATE_ADD);
|
2009-01-29 22:15:15 +00:00
|
|
|
|
2010-07-01 20:58:00 +00:00
|
|
|
stack();
|
|
|
|
|
2011-10-03 16:39:12 -05:00
|
|
|
move_step = 0;
|
|
|
|
switch (args->id) {
|
|
|
|
case SWM_ARG_ID_MOVELEFT:
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) -= (SWM_MOVE_STEPS - border_width);
|
2011-10-03 16:39:12 -05:00
|
|
|
move_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MOVERIGHT:
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) += (SWM_MOVE_STEPS - border_width);
|
2011-10-03 16:39:12 -05:00
|
|
|
move_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MOVEUP:
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) -= (SWM_MOVE_STEPS - border_width);
|
2011-10-03 16:39:12 -05:00
|
|
|
move_step = 1;
|
|
|
|
break;
|
|
|
|
case SWM_ARG_ID_MOVEDOWN:
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) += (SWM_MOVE_STEPS - border_width);
|
2011-10-03 16:39:12 -05:00
|
|
|
move_step = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (move_step) {
|
2012-01-22 03:38:04 +08:00
|
|
|
constrain_window(win, r, 0);
|
|
|
|
update_window(win);
|
2012-01-29 01:29:31 +08:00
|
|
|
store_float_geom(win, r);
|
2011-10-03 16:39:12 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-29 22:15:15 +00:00
|
|
|
if (XGrabPointer(display, win->id, False, MOUSEMASK, GrabModeAsync,
|
2012-01-22 03:38:04 +08:00
|
|
|
GrabModeAsync, None, XCreateFontCursor(display, XC_fleur),
|
|
|
|
CurrentTime) != GrabSuccess)
|
2009-01-29 22:15:15 +00:00
|
|
|
return;
|
2012-01-22 03:38:04 +08:00
|
|
|
|
|
|
|
/* get cursor offset from window root */
|
|
|
|
if (!XQueryPointer(display, win->id, &rr, &cr, &x, &y, &wx, &wy, &mask))
|
|
|
|
return;
|
|
|
|
|
2009-01-29 22:15:15 +00:00
|
|
|
do {
|
|
|
|
XMaskEvent(display, MOUSEMASK | ExposureMask |
|
|
|
|
SubstructureRedirectMask, &ev);
|
2011-06-14 22:20:55 +00:00
|
|
|
switch (ev.type) {
|
2009-01-29 22:15:15 +00:00
|
|
|
case ConfigureRequest:
|
|
|
|
case Expose:
|
|
|
|
case MapRequest:
|
|
|
|
handler[ev.type](&ev);
|
|
|
|
break;
|
|
|
|
case MotionNotify:
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = ev.xmotion.x_root - wx - border_width;
|
|
|
|
Y(win) = ev.xmotion.y_root - wy - border_width;
|
2009-10-13 17:22:42 +00:00
|
|
|
|
2012-01-22 03:38:04 +08:00
|
|
|
constrain_window(win, r, 0);
|
2009-02-01 01:39:25 +00:00
|
|
|
|
2011-03-11 14:12:49 +00:00
|
|
|
/* not free, don't sync more than 120 times / second */
|
|
|
|
if ((ev.xmotion.time - time) > (1000 / 120) ) {
|
2009-02-01 01:39:25 +00:00
|
|
|
time = ev.xmotion.time;
|
|
|
|
XSync(display, False);
|
2012-01-22 03:38:04 +08:00
|
|
|
update_window(win);
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
2009-01-29 22:15:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (ev.type != ButtonRelease);
|
2009-02-01 01:39:25 +00:00
|
|
|
if (time) {
|
|
|
|
XSync(display, False);
|
2012-01-22 03:38:04 +08:00
|
|
|
update_window(win);
|
2009-02-01 01:39:25 +00:00
|
|
|
}
|
2010-07-01 20:58:00 +00:00
|
|
|
store_float_geom(win,r);
|
2009-01-29 22:15:15 +00:00
|
|
|
XUngrabPointer(display, CurrentTime);
|
|
|
|
|
|
|
|
/* drain events */
|
2011-06-09 21:15:29 +00:00
|
|
|
drain_enter_notify();
|
2009-01-22 03:46:13 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 16:39:12 -05:00
|
|
|
void
|
|
|
|
move_step(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
struct ws_win *win = NULL;
|
|
|
|
|
2011-10-19 21:50:02 -04:00
|
|
|
if (r && r->ws && r->ws->focus)
|
2011-10-03 16:39:12 -05:00
|
|
|
win = r->ws->focus;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(win->transient != 0 || win->floating != 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
move(win, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 23:22:31 +00:00
|
|
|
/* user/key callable function IDs */
|
|
|
|
enum keyfuncid {
|
|
|
|
kf_cycle_layout,
|
2012-02-08 01:17:20 +08:00
|
|
|
kf_flip_layout,
|
2010-01-13 23:22:31 +00:00
|
|
|
kf_stack_reset,
|
|
|
|
kf_master_shrink,
|
|
|
|
kf_master_grow,
|
|
|
|
kf_master_add,
|
|
|
|
kf_master_del,
|
|
|
|
kf_stack_inc,
|
|
|
|
kf_stack_dec,
|
|
|
|
kf_swap_main,
|
|
|
|
kf_focus_next,
|
|
|
|
kf_focus_prev,
|
|
|
|
kf_swap_next,
|
|
|
|
kf_swap_prev,
|
|
|
|
kf_spawn_term,
|
|
|
|
kf_quit,
|
|
|
|
kf_restart,
|
|
|
|
kf_focus_main,
|
|
|
|
kf_ws_1,
|
|
|
|
kf_ws_2,
|
|
|
|
kf_ws_3,
|
|
|
|
kf_ws_4,
|
|
|
|
kf_ws_5,
|
|
|
|
kf_ws_6,
|
|
|
|
kf_ws_7,
|
|
|
|
kf_ws_8,
|
|
|
|
kf_ws_9,
|
|
|
|
kf_ws_10,
|
2012-04-08 01:59:41 +08:00
|
|
|
kf_ws_11,
|
|
|
|
kf_ws_12,
|
|
|
|
kf_ws_13,
|
|
|
|
kf_ws_14,
|
|
|
|
kf_ws_15,
|
|
|
|
kf_ws_16,
|
|
|
|
kf_ws_17,
|
|
|
|
kf_ws_18,
|
|
|
|
kf_ws_19,
|
|
|
|
kf_ws_20,
|
|
|
|
kf_ws_21,
|
|
|
|
kf_ws_22,
|
2010-01-13 23:22:31 +00:00
|
|
|
kf_ws_next,
|
|
|
|
kf_ws_prev,
|
2011-11-28 22:41:58 -05:00
|
|
|
kf_ws_next_all,
|
|
|
|
kf_ws_prev_all,
|
2010-07-01 19:01:15 +00:00
|
|
|
kf_ws_prior,
|
2010-01-13 23:22:31 +00:00
|
|
|
kf_screen_next,
|
|
|
|
kf_screen_prev,
|
|
|
|
kf_mvws_1,
|
|
|
|
kf_mvws_2,
|
|
|
|
kf_mvws_3,
|
|
|
|
kf_mvws_4,
|
|
|
|
kf_mvws_5,
|
|
|
|
kf_mvws_6,
|
|
|
|
kf_mvws_7,
|
|
|
|
kf_mvws_8,
|
|
|
|
kf_mvws_9,
|
|
|
|
kf_mvws_10,
|
2012-04-08 01:59:41 +08:00
|
|
|
kf_mvws_11,
|
|
|
|
kf_mvws_12,
|
|
|
|
kf_mvws_13,
|
|
|
|
kf_mvws_14,
|
|
|
|
kf_mvws_15,
|
|
|
|
kf_mvws_16,
|
|
|
|
kf_mvws_17,
|
|
|
|
kf_mvws_18,
|
|
|
|
kf_mvws_19,
|
|
|
|
kf_mvws_20,
|
|
|
|
kf_mvws_21,
|
|
|
|
kf_mvws_22,
|
2010-01-13 23:22:31 +00:00
|
|
|
kf_bar_toggle,
|
|
|
|
kf_wind_kill,
|
|
|
|
kf_wind_del,
|
|
|
|
kf_float_toggle,
|
|
|
|
kf_version,
|
|
|
|
kf_spawn_custom,
|
2011-06-06 19:52:03 +00:00
|
|
|
kf_iconify,
|
|
|
|
kf_uniconify,
|
2011-06-24 16:53:40 +00:00
|
|
|
kf_raise_toggle,
|
2011-08-08 22:41:51 +00:00
|
|
|
kf_button2,
|
2011-10-03 16:39:12 -05:00
|
|
|
kf_width_shrink,
|
|
|
|
kf_width_grow,
|
|
|
|
kf_height_shrink,
|
|
|
|
kf_height_grow,
|
|
|
|
kf_move_left,
|
|
|
|
kf_move_right,
|
|
|
|
kf_move_up,
|
|
|
|
kf_move_down,
|
2011-11-28 23:25:46 -05:00
|
|
|
kf_name_workspace,
|
|
|
|
kf_search_workspace,
|
2011-11-28 23:41:37 -05:00
|
|
|
kf_search_win,
|
2011-06-06 19:52:03 +00:00
|
|
|
kf_dumpwins, /* MUST BE LAST */
|
2010-01-13 23:22:31 +00:00
|
|
|
kf_invalid
|
|
|
|
};
|
|
|
|
|
2009-03-10 01:32:06 +00:00
|
|
|
/* key definitions */
|
2009-10-01 21:51:50 +00:00
|
|
|
void
|
|
|
|
dummykeyfunc(struct swm_region *r, union arg *args)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2009-03-10 01:32:06 +00:00
|
|
|
struct keyfunc {
|
|
|
|
char name[SWM_FUNCNAME_LEN];
|
|
|
|
void (*func)(struct swm_region *r, union arg *);
|
|
|
|
union arg args;
|
2009-09-12 21:32:21 +00:00
|
|
|
} keyfuncs[kf_invalid + 1] = {
|
2009-03-10 01:32:06 +00:00
|
|
|
/* name function argument */
|
2009-08-30 18:16:41 +00:00
|
|
|
{ "cycle_layout", cycle_layout, {0} },
|
2012-02-08 01:17:20 +08:00
|
|
|
{ "flip_layout", stack_config, {.id = SWM_ARG_ID_FLIPLAYOUT} },
|
2009-08-30 18:16:41 +00:00
|
|
|
{ "stack_reset", stack_config, {.id = SWM_ARG_ID_STACKRESET} },
|
2009-03-10 01:32:06 +00:00
|
|
|
{ "master_shrink", stack_config, {.id = SWM_ARG_ID_MASTERSHRINK} },
|
|
|
|
{ "master_grow", stack_config, {.id = SWM_ARG_ID_MASTERGROW} },
|
|
|
|
{ "master_add", stack_config, {.id = SWM_ARG_ID_MASTERADD} },
|
|
|
|
{ "master_del", stack_config, {.id = SWM_ARG_ID_MASTERDEL} },
|
|
|
|
{ "stack_inc", stack_config, {.id = SWM_ARG_ID_STACKINC} },
|
|
|
|
{ "stack_dec", stack_config, {.id = SWM_ARG_ID_STACKDEC} },
|
|
|
|
{ "swap_main", swapwin, {.id = SWM_ARG_ID_SWAPMAIN} },
|
|
|
|
{ "focus_next", focus, {.id = SWM_ARG_ID_FOCUSNEXT} },
|
|
|
|
{ "focus_prev", focus, {.id = SWM_ARG_ID_FOCUSPREV} },
|
|
|
|
{ "swap_next", swapwin, {.id = SWM_ARG_ID_SWAPNEXT} },
|
|
|
|
{ "swap_prev", swapwin, {.id = SWM_ARG_ID_SWAPPREV} },
|
|
|
|
{ "spawn_term", spawnterm, {.argv = spawn_term} },
|
|
|
|
{ "quit", quit, {0} },
|
|
|
|
{ "restart", restart, {0} },
|
|
|
|
{ "focus_main", focus, {.id = SWM_ARG_ID_FOCUSMAIN} },
|
|
|
|
{ "ws_1", switchws, {.id = 0} },
|
|
|
|
{ "ws_2", switchws, {.id = 1} },
|
|
|
|
{ "ws_3", switchws, {.id = 2} },
|
|
|
|
{ "ws_4", switchws, {.id = 3} },
|
|
|
|
{ "ws_5", switchws, {.id = 4} },
|
|
|
|
{ "ws_6", switchws, {.id = 5} },
|
|
|
|
{ "ws_7", switchws, {.id = 6} },
|
|
|
|
{ "ws_8", switchws, {.id = 7} },
|
|
|
|
{ "ws_9", switchws, {.id = 8} },
|
|
|
|
{ "ws_10", switchws, {.id = 9} },
|
2012-04-08 01:59:41 +08:00
|
|
|
{ "ws_11", switchws, {.id = 10} },
|
|
|
|
{ "ws_12", switchws, {.id = 11} },
|
|
|
|
{ "ws_13", switchws, {.id = 12} },
|
|
|
|
{ "ws_14", switchws, {.id = 13} },
|
|
|
|
{ "ws_15", switchws, {.id = 14} },
|
|
|
|
{ "ws_16", switchws, {.id = 15} },
|
|
|
|
{ "ws_17", switchws, {.id = 16} },
|
|
|
|
{ "ws_18", switchws, {.id = 17} },
|
|
|
|
{ "ws_19", switchws, {.id = 18} },
|
|
|
|
{ "ws_20", switchws, {.id = 19} },
|
|
|
|
{ "ws_21", switchws, {.id = 20} },
|
|
|
|
{ "ws_22", switchws, {.id = 21} },
|
2009-08-30 18:16:41 +00:00
|
|
|
{ "ws_next", cyclews, {.id = SWM_ARG_ID_CYCLEWS_UP} },
|
|
|
|
{ "ws_prev", cyclews, {.id = SWM_ARG_ID_CYCLEWS_DOWN} },
|
2011-11-28 22:41:58 -05:00
|
|
|
{ "ws_next_all", cyclews, {.id = SWM_ARG_ID_CYCLEWS_UP_ALL} },
|
|
|
|
{ "ws_prev_all", cyclews, {.id = SWM_ARG_ID_CYCLEWS_DOWN_ALL} },
|
2010-07-01 19:01:15 +00:00
|
|
|
{ "ws_prior", priorws, {0} },
|
2009-08-30 18:16:41 +00:00
|
|
|
{ "screen_next", cyclescr, {.id = SWM_ARG_ID_CYCLESC_UP} },
|
|
|
|
{ "screen_prev", cyclescr, {.id = SWM_ARG_ID_CYCLESC_DOWN} },
|
2009-03-10 01:32:06 +00:00
|
|
|
{ "mvws_1", send_to_ws, {.id = 0} },
|
|
|
|
{ "mvws_2", send_to_ws, {.id = 1} },
|
|
|
|
{ "mvws_3", send_to_ws, {.id = 2} },
|
|
|
|
{ "mvws_4", send_to_ws, {.id = 3} },
|
|
|
|
{ "mvws_5", send_to_ws, {.id = 4} },
|
|
|
|
{ "mvws_6", send_to_ws, {.id = 5} },
|
|
|
|
{ "mvws_7", send_to_ws, {.id = 6} },
|
|
|
|
{ "mvws_8", send_to_ws, {.id = 7} },
|
|
|
|
{ "mvws_9", send_to_ws, {.id = 8} },
|
|
|
|
{ "mvws_10", send_to_ws, {.id = 9} },
|
2012-04-08 01:59:41 +08:00
|
|
|
{ "mvws_11", send_to_ws, {.id = 10} },
|
|
|
|
{ "mvws_12", send_to_ws, {.id = 11} },
|
|
|
|
{ "mvws_13", send_to_ws, {.id = 12} },
|
|
|
|
{ "mvws_14", send_to_ws, {.id = 13} },
|
|
|
|
{ "mvws_15", send_to_ws, {.id = 14} },
|
|
|
|
{ "mvws_16", send_to_ws, {.id = 15} },
|
|
|
|
{ "mvws_17", send_to_ws, {.id = 16} },
|
|
|
|
{ "mvws_18", send_to_ws, {.id = 17} },
|
|
|
|
{ "mvws_19", send_to_ws, {.id = 18} },
|
|
|
|
{ "mvws_20", send_to_ws, {.id = 19} },
|
|
|
|
{ "mvws_21", send_to_ws, {.id = 20} },
|
|
|
|
{ "mvws_22", send_to_ws, {.id = 21} },
|
2009-03-10 01:32:06 +00:00
|
|
|
{ "bar_toggle", bar_toggle, {0} },
|
|
|
|
{ "wind_kill", wkill, {.id = SWM_ARG_ID_KILLWINDOW} },
|
|
|
|
{ "wind_del", wkill, {.id = SWM_ARG_ID_DELETEWINDOW} },
|
|
|
|
{ "float_toggle", floating_toggle,{0} },
|
|
|
|
{ "version", version, {0} },
|
2009-09-12 21:32:21 +00:00
|
|
|
{ "spawn_custom", dummykeyfunc, {0} },
|
2011-06-06 19:52:03 +00:00
|
|
|
{ "iconify", iconify, {0} },
|
|
|
|
{ "uniconify", uniconify, {0} },
|
2011-06-24 16:53:40 +00:00
|
|
|
{ "raise_toggle", raise_toggle, {0} },
|
2011-08-08 22:41:51 +00:00
|
|
|
{ "button2", pressbutton, {2} },
|
2011-10-03 16:39:12 -05:00
|
|
|
{ "width_shrink", resize_step, {.id = SWM_ARG_ID_WIDTHSHRINK} },
|
|
|
|
{ "width_grow", resize_step, {.id = SWM_ARG_ID_WIDTHGROW} },
|
|
|
|
{ "height_shrink", resize_step, {.id = SWM_ARG_ID_HEIGHTSHRINK} },
|
|
|
|
{ "height_grow", resize_step, {.id = SWM_ARG_ID_HEIGHTGROW} },
|
|
|
|
{ "move_left", move_step, {.id = SWM_ARG_ID_MOVELEFT} },
|
|
|
|
{ "move_right", move_step, {.id = SWM_ARG_ID_MOVERIGHT} },
|
|
|
|
{ "move_up", move_step, {.id = SWM_ARG_ID_MOVEUP} },
|
|
|
|
{ "move_down", move_step, {.id = SWM_ARG_ID_MOVEDOWN} },
|
2011-11-28 23:25:46 -05:00
|
|
|
{ "name_workspace", name_workspace, {0} },
|
|
|
|
{ "search_workspace", search_workspace, {0} },
|
2011-11-28 23:41:37 -05:00
|
|
|
{ "search_win", search_win, {0} },
|
2011-06-06 19:52:03 +00:00
|
|
|
{ "dumpwins", dumpwins, {0} }, /* MUST BE LAST */
|
2009-09-12 21:32:21 +00:00
|
|
|
{ "invalid key func", NULL, {0} },
|
2009-03-10 01:32:06 +00:00
|
|
|
};
|
|
|
|
struct key {
|
2012-02-09 17:19:00 +00:00
|
|
|
RB_ENTRY(key) entry;
|
2009-03-10 01:32:06 +00:00
|
|
|
unsigned int mod;
|
|
|
|
KeySym keysym;
|
|
|
|
enum keyfuncid funcid;
|
2009-09-12 21:32:21 +00:00
|
|
|
char *spawn_name;
|
2009-03-10 01:32:06 +00:00
|
|
|
};
|
2012-05-24 21:41:58 +01:00
|
|
|
RB_HEAD(key_tree, key);
|
2012-02-09 17:19:00 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
key_cmp(struct key *kp1, struct key *kp2)
|
|
|
|
{
|
|
|
|
if (kp1->keysym < kp2->keysym)
|
|
|
|
return (-1);
|
|
|
|
if (kp1->keysym > kp2->keysym)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (kp1->mod < kp2->mod)
|
|
|
|
return (-1);
|
|
|
|
if (kp1->mod > kp2->mod)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-05-24 21:42:46 +01:00
|
|
|
RB_GENERATE(key_tree, key, entry, key_cmp);
|
2012-05-24 21:41:58 +01:00
|
|
|
struct key_tree keys;
|
2009-03-10 01:32:06 +00:00
|
|
|
|
2009-01-22 00:08:19 +00:00
|
|
|
/* mouse */
|
|
|
|
enum { client_click, root_click };
|
|
|
|
struct button {
|
2009-01-22 03:46:13 +00:00
|
|
|
unsigned int action;
|
2009-01-22 00:08:19 +00:00
|
|
|
unsigned int mask;
|
|
|
|
unsigned int button;
|
2009-01-29 21:38:49 +00:00
|
|
|
void (*func)(struct ws_win *, union arg *);
|
2009-01-22 00:08:19 +00:00
|
|
|
union arg args;
|
|
|
|
} buttons[] = {
|
2009-08-30 18:16:41 +00:00
|
|
|
/* action key mouse button func args */
|
|
|
|
{ client_click, MODKEY, Button3, resize, {.id = SWM_ARG_ID_DONTCENTER} },
|
|
|
|
{ client_click, MODKEY | ShiftMask, Button3, resize, {.id = SWM_ARG_ID_CENTER} },
|
|
|
|
{ client_click, MODKEY, Button1, move, {0} },
|
2009-01-22 00:08:19 +00:00
|
|
|
};
|
|
|
|
|
2009-02-16 00:03:53 +00:00
|
|
|
void
|
|
|
|
update_modkey(unsigned int mod)
|
|
|
|
{
|
2012-02-02 22:55:56 +00:00
|
|
|
int i;
|
|
|
|
struct key *kp;
|
2009-02-16 00:03:53 +00:00
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
mod_key = mod;
|
2012-05-24 21:41:58 +01:00
|
|
|
RB_FOREACH(kp, key_tree, &keys)
|
2012-02-02 21:19:17 +00:00
|
|
|
if (kp->mod & ShiftMask)
|
|
|
|
kp->mod = mod | ShiftMask;
|
2009-02-16 00:03:53 +00:00
|
|
|
else
|
2012-02-02 21:19:17 +00:00
|
|
|
kp->mod = mod;
|
2009-02-16 00:03:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(buttons); i++)
|
|
|
|
if (buttons[i].mask & ShiftMask)
|
|
|
|
buttons[i].mask = mod | ShiftMask;
|
|
|
|
else
|
|
|
|
buttons[i].mask = mod;
|
|
|
|
}
|
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
/* spawn */
|
|
|
|
struct spawn_prog {
|
2012-02-07 23:35:14 +00:00
|
|
|
TAILQ_ENTRY(spawn_prog) entry;
|
2009-09-12 21:32:21 +00:00
|
|
|
char *name;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
};
|
2012-02-07 23:35:14 +00:00
|
|
|
TAILQ_HEAD(spawn_list, spawn_prog);
|
|
|
|
struct spawn_list spawns = TAILQ_HEAD_INITIALIZER(spawns);
|
2009-09-12 21:32:21 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
int
|
|
|
|
spawn_expand(struct swm_region *r, union arg *args, char *spawn_name,
|
|
|
|
char ***ret_args)
|
2009-09-12 21:32:21 +00:00
|
|
|
{
|
|
|
|
struct spawn_prog *prog = NULL;
|
|
|
|
int i;
|
|
|
|
char *ap, **real_args;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_expand: %s\n", spawn_name);
|
2009-09-12 21:32:21 +00:00
|
|
|
|
|
|
|
/* find program */
|
2012-02-07 23:35:14 +00:00
|
|
|
TAILQ_FOREACH(prog, &spawns, entry) {
|
|
|
|
if (!strcasecmp(spawn_name, prog->name))
|
|
|
|
break;
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
|
|
|
if (prog == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("spawn_custom: program %s not found", spawn_name);
|
2011-06-06 19:52:03 +00:00
|
|
|
return (-1);
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make room for expanded args */
|
|
|
|
if ((real_args = calloc(prog->argc + 1, sizeof(char *))) == NULL)
|
|
|
|
err(1, "spawn_custom: calloc real_args");
|
|
|
|
|
|
|
|
/* expand spawn_args into real_args */
|
|
|
|
for (i = 0; i < prog->argc; i++) {
|
|
|
|
ap = prog->argv[i];
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_custom: raw arg: %s\n", ap);
|
2009-09-12 21:32:21 +00:00
|
|
|
if (!strcasecmp(ap, "$bar_border")) {
|
|
|
|
if ((real_args[i] =
|
|
|
|
strdup(r->s->c[SWM_S_COLOR_BAR_BORDER].name))
|
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom border color");
|
|
|
|
} else if (!strcasecmp(ap, "$bar_color")) {
|
|
|
|
if ((real_args[i] =
|
|
|
|
strdup(r->s->c[SWM_S_COLOR_BAR].name))
|
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom bar color");
|
|
|
|
} else if (!strcasecmp(ap, "$bar_font")) {
|
2012-02-02 07:00:45 +08:00
|
|
|
if ((real_args[i] = strdup(bar_fonts))
|
2009-09-12 21:32:21 +00:00
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom bar fonts");
|
|
|
|
} else if (!strcasecmp(ap, "$bar_font_color")) {
|
|
|
|
if ((real_args[i] =
|
|
|
|
strdup(r->s->c[SWM_S_COLOR_BAR_FONT].name))
|
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom color font");
|
|
|
|
} else if (!strcasecmp(ap, "$color_focus")) {
|
|
|
|
if ((real_args[i] =
|
|
|
|
strdup(r->s->c[SWM_S_COLOR_FOCUS].name))
|
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom color focus");
|
|
|
|
} else if (!strcasecmp(ap, "$color_unfocus")) {
|
|
|
|
if ((real_args[i] =
|
|
|
|
strdup(r->s->c[SWM_S_COLOR_UNFOCUS].name))
|
|
|
|
== NULL)
|
|
|
|
err(1, "spawn_custom color unfocus");
|
|
|
|
} else {
|
|
|
|
/* no match --> copy as is */
|
|
|
|
if ((real_args[i] = strdup(ap)) == NULL)
|
|
|
|
err(1, "spawn_custom strdup(ap)");
|
|
|
|
}
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_custom: cooked arg: %s\n",
|
2009-09-12 21:32:21 +00:00
|
|
|
real_args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWM_DEBUG
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_custom: result: ");
|
|
|
|
for (i = 0; i < prog->argc; i++)
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "\"%s\" ", real_args[i]);
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "\n");
|
2009-09-12 21:32:21 +00:00
|
|
|
#endif
|
2011-06-06 19:52:03 +00:00
|
|
|
*ret_args = real_args;
|
|
|
|
return (prog->argc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spawn_custom(struct swm_region *r, union arg *args, char *spawn_name)
|
|
|
|
{
|
|
|
|
union arg a;
|
|
|
|
char **real_args;
|
|
|
|
int spawn_argc, i;
|
2009-09-12 21:32:21 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if ((spawn_argc = spawn_expand(r, args, spawn_name, &real_args)) < 0)
|
|
|
|
return;
|
2009-09-12 21:32:21 +00:00
|
|
|
a.argv = real_args;
|
2011-06-06 19:52:03 +00:00
|
|
|
if (fork() == 0)
|
2011-06-23 02:15:53 +00:00
|
|
|
spawn(r->ws->idx, &a, 1);
|
2011-06-06 19:52:03 +00:00
|
|
|
|
|
|
|
for (i = 0; i < spawn_argc; i++)
|
|
|
|
free(real_args[i]);
|
|
|
|
free(real_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spawn_select(struct swm_region *r, union arg *args, char *spawn_name, int *pid)
|
|
|
|
{
|
|
|
|
union arg a;
|
|
|
|
char **real_args;
|
|
|
|
int i, spawn_argc;
|
|
|
|
|
|
|
|
if ((spawn_argc = spawn_expand(r, args, spawn_name, &real_args)) < 0)
|
|
|
|
return;
|
|
|
|
a.argv = real_args;
|
|
|
|
|
|
|
|
if (pipe(select_list_pipe) == -1)
|
|
|
|
err(1, "pipe error");
|
|
|
|
if (pipe(select_resp_pipe) == -1)
|
|
|
|
err(1, "pipe error");
|
|
|
|
|
|
|
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
|
|
|
err(1, "could not disable SIGPIPE");
|
|
|
|
switch (*pid = fork()) {
|
|
|
|
case -1:
|
|
|
|
err(1, "cannot fork");
|
|
|
|
break;
|
|
|
|
case 0: /* child */
|
|
|
|
if (dup2(select_list_pipe[0], 0) == -1)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "dup2");
|
2011-06-06 19:52:03 +00:00
|
|
|
if (dup2(select_resp_pipe[1], 1) == -1)
|
2011-12-07 21:53:12 -05:00
|
|
|
err(1, "dup2");
|
2011-06-06 19:52:03 +00:00
|
|
|
close(select_list_pipe[1]);
|
|
|
|
close(select_resp_pipe[0]);
|
2011-06-23 02:15:53 +00:00
|
|
|
spawn(r->ws->idx, &a, 0);
|
2011-06-06 19:52:03 +00:00
|
|
|
break;
|
|
|
|
default: /* parent */
|
|
|
|
close(select_list_pipe[0]);
|
|
|
|
close(select_resp_pipe[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < spawn_argc; i++)
|
2009-09-12 21:32:21 +00:00
|
|
|
free(real_args[i]);
|
|
|
|
free(real_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-07 23:35:14 +00:00
|
|
|
spawn_insert(char *name, char *args)
|
2009-09-12 21:32:21 +00:00
|
|
|
{
|
2012-02-07 23:35:14 +00:00
|
|
|
char *arg, *cp, *ptr;
|
|
|
|
struct spawn_prog *sp;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_insert: %s\n", name);
|
|
|
|
|
|
|
|
if ((sp = calloc(1, sizeof *sp)) == NULL)
|
|
|
|
err(1, "spawn_insert: malloc");
|
|
|
|
if ((sp->name = strdup(name)) == NULL)
|
|
|
|
err(1, "spawn_insert: strdup");
|
|
|
|
|
|
|
|
/* convert the arguments to an argument list */
|
|
|
|
if ((ptr = cp = strdup(args)) == NULL)
|
|
|
|
err(1, "spawn_insert: strdup");
|
|
|
|
while ((arg = strsep(&ptr, " \t")) != NULL) {
|
|
|
|
/* empty field; skip it */
|
|
|
|
if (*arg == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sp->argc++;
|
|
|
|
if ((sp->argv = realloc(sp->argv, sp->argc *
|
|
|
|
sizeof *sp->argv)) == NULL)
|
|
|
|
err(1, "spawn_insert: realloc");
|
|
|
|
if ((sp->argv[sp->argc - 1] = strdup(arg)) == NULL)
|
|
|
|
err(1, "spawn_insert: strdup");
|
|
|
|
}
|
|
|
|
free(cp);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&spawns, sp, entry);
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_insert: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spawn_remove(struct spawn_prog *sp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_remove: %s\n", sp->name);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&spawns, sp, entry);
|
|
|
|
for (i = 0; i < sp->argc; i++)
|
|
|
|
free(sp->argv[i]);
|
|
|
|
free(sp->argv);
|
|
|
|
free(sp->name);
|
|
|
|
free(sp);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_remove: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spawn_replace(struct spawn_prog *sp, char *name, char *args)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_replace: %s [%s]\n", sp->name, name);
|
|
|
|
|
|
|
|
spawn_remove(sp);
|
|
|
|
spawn_insert(name, args);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "spawn_replace: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setspawn(char *name, char *args)
|
|
|
|
{
|
|
|
|
struct spawn_prog *sp;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setspawn: %s\n", name);
|
2009-09-12 21:32:21 +00:00
|
|
|
|
2012-02-07 23:35:14 +00:00
|
|
|
if (name == NULL)
|
2009-09-12 21:32:21 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-07 23:35:14 +00:00
|
|
|
TAILQ_FOREACH(sp, &spawns, entry) {
|
|
|
|
if (!strcmp(sp->name, name)) {
|
|
|
|
if (*args == '\0')
|
|
|
|
spawn_remove(sp);
|
|
|
|
else
|
|
|
|
spawn_replace(sp, name, args);
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setspawn: leave\n");
|
2009-09-12 21:32:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-02-07 23:35:14 +00:00
|
|
|
if (*args == '\0') {
|
|
|
|
warnx("error: setspawn: cannot find program: %s", name);
|
2009-09-12 21:32:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-07 23:35:14 +00:00
|
|
|
spawn_insert(name, args);
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setspawn: leave\n");
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setconfspawn(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setconfspawn: [%s] [%s]\n", selector, value);
|
|
|
|
|
2012-02-07 23:35:14 +00:00
|
|
|
setspawn(selector, value);
|
2009-09-12 21:32:21 +00:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setconfspawn: done\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_spawn(void)
|
|
|
|
{
|
|
|
|
setconfspawn("term", "xterm", 0);
|
|
|
|
setconfspawn("screenshot_all", "screenshot.sh full", 0);
|
|
|
|
setconfspawn("screenshot_wind", "screenshot.sh window", 0);
|
|
|
|
setconfspawn("lock", "xlock", 0);
|
|
|
|
setconfspawn("initscr", "initscreen.sh", 0);
|
|
|
|
setconfspawn("menu", "dmenu_run"
|
|
|
|
" -fn $bar_font"
|
|
|
|
" -nb $bar_color"
|
|
|
|
" -nf $bar_font_color"
|
|
|
|
" -sb $bar_border"
|
2009-09-17 02:11:34 +00:00
|
|
|
" -sf $bar_color", 0);
|
2011-11-28 23:15:28 -05:00
|
|
|
setconfspawn("search", "dmenu"
|
2011-06-06 19:52:03 +00:00
|
|
|
" -i"
|
|
|
|
" -fn $bar_font"
|
|
|
|
" -nb $bar_color"
|
|
|
|
" -nf $bar_font_color"
|
|
|
|
" -sb $bar_border"
|
|
|
|
" -sf $bar_color", 0);
|
2011-11-28 23:25:46 -05:00
|
|
|
setconfspawn("name_workspace", "dmenu"
|
|
|
|
" -p Workspace"
|
|
|
|
" -fn $bar_font"
|
|
|
|
" -nb $bar_color"
|
|
|
|
" -nf $bar_font_color"
|
|
|
|
" -sb $bar_border"
|
|
|
|
" -sf $bar_color", 0);
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* key bindings */
|
2009-03-10 01:32:06 +00:00
|
|
|
#define SWM_MODNAME_SIZE 32
|
|
|
|
#define SWM_KEY_WS "\n+ \t"
|
|
|
|
int
|
|
|
|
parsekeys(char *keystr, unsigned int currmod, unsigned int *mod, KeySym *ks)
|
|
|
|
{
|
|
|
|
char *cp, *name;
|
|
|
|
KeySym uks;
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "parsekeys: enter [%s]\n", keystr);
|
|
|
|
if (mod == NULL || ks == NULL) {
|
|
|
|
DNPRINTF(SWM_D_KEY, "parsekeys: no mod or key vars\n");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (keystr == NULL || strlen(keystr) == 0) {
|
|
|
|
DNPRINTF(SWM_D_KEY, "parsekeys: no keystr\n");
|
|
|
|
return (1);
|
|
|
|
}
|
2009-03-10 01:32:06 +00:00
|
|
|
cp = keystr;
|
2009-09-12 21:32:21 +00:00
|
|
|
*ks = NoSymbol;
|
2009-03-10 01:32:06 +00:00
|
|
|
*mod = 0;
|
|
|
|
while ((name = strsep(&cp, SWM_KEY_WS)) != NULL) {
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "parsekeys: key [%s]\n", name);
|
2009-03-10 01:32:06 +00:00
|
|
|
if (cp)
|
|
|
|
cp += (long)strspn(cp, SWM_KEY_WS);
|
|
|
|
if (strncasecmp(name, "MOD", SWM_MODNAME_SIZE) == 0)
|
|
|
|
*mod |= currmod;
|
|
|
|
else if (!strncasecmp(name, "Mod1", SWM_MODNAME_SIZE))
|
|
|
|
*mod |= Mod1Mask;
|
|
|
|
else if (!strncasecmp(name, "Mod2", SWM_MODNAME_SIZE))
|
|
|
|
*mod += Mod2Mask;
|
|
|
|
else if (!strncmp(name, "Mod3", SWM_MODNAME_SIZE))
|
|
|
|
*mod |= Mod3Mask;
|
|
|
|
else if (!strncmp(name, "Mod4", SWM_MODNAME_SIZE))
|
|
|
|
*mod |= Mod4Mask;
|
|
|
|
else if (strncasecmp(name, "SHIFT", SWM_MODNAME_SIZE) == 0)
|
|
|
|
*mod |= ShiftMask;
|
2009-05-28 19:40:13 +00:00
|
|
|
else if (strncasecmp(name, "CONTROL", SWM_MODNAME_SIZE) == 0)
|
|
|
|
*mod |= ControlMask;
|
2009-03-10 01:32:06 +00:00
|
|
|
else {
|
|
|
|
*ks = XStringToKeysym(name);
|
|
|
|
XConvertCase(*ks, ks, &uks);
|
|
|
|
if (ks == NoSymbol) {
|
|
|
|
DNPRINTF(SWM_D_KEY,
|
|
|
|
"parsekeys: invalid key %s\n",
|
|
|
|
name);
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
2009-03-10 01:32:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "parsekeys: leave ok\n");
|
|
|
|
return (0);
|
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
char *
|
|
|
|
strdupsafe(char *str)
|
|
|
|
{
|
|
|
|
if (str == NULL)
|
|
|
|
return (NULL);
|
|
|
|
else
|
|
|
|
return (strdup(str));
|
2009-03-10 01:32:06 +00:00
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2012-02-02 21:19:17 +00:00
|
|
|
void
|
|
|
|
key_insert(unsigned int mod, KeySym ks, enum keyfuncid kfid, char *spawn_name)
|
|
|
|
{
|
2012-02-02 22:55:56 +00:00
|
|
|
struct key *kp;
|
2012-02-02 21:19:17 +00:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_insert: enter %s [%s]\n",
|
|
|
|
keyfuncs[kfid].name, spawn_name);
|
|
|
|
|
|
|
|
if ((kp = malloc(sizeof *kp)) == NULL)
|
|
|
|
err(1, "key_insert: malloc");
|
|
|
|
|
|
|
|
kp->mod = mod;
|
|
|
|
kp->keysym = ks;
|
|
|
|
kp->funcid = kfid;
|
|
|
|
kp->spawn_name = strdupsafe(spawn_name);
|
2012-05-24 21:41:58 +01:00
|
|
|
RB_INSERT(key_tree, &keys, kp);
|
2012-02-02 21:19:17 +00:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_insert: leave\n");
|
|
|
|
}
|
|
|
|
|
2012-02-09 17:19:00 +00:00
|
|
|
struct key *
|
|
|
|
key_lookup(unsigned int mod, KeySym ks)
|
|
|
|
{
|
|
|
|
struct key kp;
|
|
|
|
|
|
|
|
kp.keysym = ks;
|
|
|
|
kp.mod = mod;
|
|
|
|
|
2012-05-24 21:41:58 +01:00
|
|
|
return (RB_FIND(key_tree, &keys, &kp));
|
2012-02-09 17:19:00 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 21:19:17 +00:00
|
|
|
void
|
|
|
|
key_remove(struct key *kp)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_remove: %s\n", keyfuncs[kp->funcid].name);
|
|
|
|
|
2012-05-24 21:41:58 +01:00
|
|
|
RB_REMOVE(key_tree, &keys, kp);
|
2012-02-02 21:19:17 +00:00
|
|
|
free(kp->spawn_name);
|
|
|
|
free(kp);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_remove: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
key_replace(struct key *kp, unsigned int mod, KeySym ks, enum keyfuncid kfid,
|
|
|
|
char *spawn_name)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_replace: %s [%s]\n", keyfuncs[kp->funcid].name,
|
|
|
|
spawn_name);
|
|
|
|
|
|
|
|
key_remove(kp);
|
|
|
|
key_insert(mod, ks, kfid, spawn_name);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_KEY, "key_replace: leave\n");
|
|
|
|
}
|
|
|
|
|
2009-03-10 01:32:06 +00:00
|
|
|
void
|
2011-06-14 22:20:55 +00:00
|
|
|
setkeybinding(unsigned int mod, KeySym ks, enum keyfuncid kfid,
|
|
|
|
char *spawn_name)
|
2009-03-10 01:32:06 +00:00
|
|
|
{
|
2012-02-02 22:55:56 +00:00
|
|
|
struct key *kp;
|
2012-02-02 21:19:17 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setkeybinding: enter %s [%s]\n",
|
|
|
|
keyfuncs[kfid].name, spawn_name);
|
2012-02-02 21:19:17 +00:00
|
|
|
|
2012-02-09 17:19:00 +00:00
|
|
|
if ((kp = key_lookup(mod, ks)) != NULL) {
|
|
|
|
if (kfid == kf_invalid)
|
|
|
|
key_remove(kp);
|
|
|
|
else
|
|
|
|
key_replace(kp, mod, ks, kfid, spawn_name);
|
|
|
|
DNPRINTF(SWM_D_KEY, "setkeybinding: leave\n");
|
|
|
|
return;
|
2009-03-10 01:32:06 +00:00
|
|
|
}
|
|
|
|
if (kfid == kf_invalid) {
|
2012-02-02 21:19:17 +00:00
|
|
|
warnx("error: setkeybinding: cannot find mod/key combination");
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setkeybinding: leave\n");
|
2009-03-10 01:32:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-02 21:19:17 +00:00
|
|
|
|
|
|
|
key_insert(mod, ks, kfid, spawn_name);
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setkeybinding: leave\n");
|
2009-03-10 01:32:06 +00:00
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
int
|
|
|
|
setconfbinding(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
enum keyfuncid kfid;
|
|
|
|
unsigned int mod;
|
|
|
|
KeySym ks;
|
2012-02-07 23:35:14 +00:00
|
|
|
struct spawn_prog *sp;
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setconfbinding: enter\n");
|
|
|
|
if (selector == NULL) {
|
|
|
|
DNPRINTF(SWM_D_KEY, "setconfbinding: unbind %s\n", value);
|
|
|
|
if (parsekeys(value, mod_key, &mod, &ks) == 0) {
|
|
|
|
kfid = kf_invalid;
|
|
|
|
setkeybinding(mod, ks, kfid, NULL);
|
|
|
|
return (0);
|
|
|
|
} else
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
/* search by key function name */
|
2009-08-11 16:20:55 +00:00
|
|
|
for (kfid = 0; kfid < kf_invalid; (kfid)++) {
|
|
|
|
if (strncasecmp(selector, keyfuncs[kfid].name,
|
|
|
|
SWM_FUNCNAME_LEN) == 0) {
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setconfbinding: %s: match\n",
|
|
|
|
selector);
|
|
|
|
if (parsekeys(value, mod_key, &mod, &ks) == 0) {
|
|
|
|
setkeybinding(mod, ks, kfid, NULL);
|
|
|
|
return (0);
|
|
|
|
} else
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* search by custom spawn name */
|
2012-02-07 23:35:14 +00:00
|
|
|
TAILQ_FOREACH(sp, &spawns, entry) {
|
|
|
|
if (strcasecmp(selector, sp->name) == 0) {
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setconfbinding: %s: match\n",
|
|
|
|
selector);
|
|
|
|
if (parsekeys(value, mod_key, &mod, &ks) == 0) {
|
|
|
|
setkeybinding(mod, ks, kf_spawn_custom,
|
2012-02-07 23:35:14 +00:00
|
|
|
sp->name);
|
2009-08-11 16:20:55 +00:00
|
|
|
return (0);
|
2009-09-12 21:32:21 +00:00
|
|
|
} else
|
|
|
|
return (1);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-12 21:32:21 +00:00
|
|
|
DNPRINTF(SWM_D_KEY, "setconfbinding: no match\n");
|
2009-08-11 16:20:55 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-03-10 01:32:06 +00:00
|
|
|
void
|
|
|
|
setup_keys(void)
|
|
|
|
{
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY, XK_space, kf_cycle_layout,NULL);
|
2012-02-08 01:17:20 +08:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_backslash, kf_flip_layout, NULL);
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_space, kf_stack_reset, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_h, kf_master_shrink,NULL);
|
|
|
|
setkeybinding(MODKEY, XK_l, kf_master_grow, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_comma, kf_master_add, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_period, kf_master_del, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_comma, kf_stack_inc, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_period, kf_stack_dec, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_Return, kf_swap_main, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_j, kf_focus_next, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_k, kf_focus_prev, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_j, kf_swap_next, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_k, kf_swap_prev, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_Return, kf_spawn_term, NULL);
|
2011-10-03 16:39:12 -05:00
|
|
|
setkeybinding(MODKEY, XK_p, kf_spawn_custom,"menu");
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_q, kf_quit, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_q, kf_restart, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_m, kf_focus_main, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_1, kf_ws_1, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_2, kf_ws_2, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_3, kf_ws_3, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_4, kf_ws_4, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_5, kf_ws_5, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_6, kf_ws_6, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_7, kf_ws_7, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_8, kf_ws_8, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_9, kf_ws_9, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_0, kf_ws_10, NULL);
|
2012-04-08 01:59:41 +08:00
|
|
|
setkeybinding(MODKEY, XK_F1, kf_ws_11, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F2, kf_ws_12, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F3, kf_ws_13, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F4, kf_ws_14, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F5, kf_ws_15, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F6, kf_ws_16, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F7, kf_ws_17, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F8, kf_ws_18, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F9, kf_ws_19, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F10, kf_ws_20, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F11, kf_ws_21, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_F12, kf_ws_22, NULL);
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY, XK_Right, kf_ws_next, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_Left, kf_ws_prev, NULL);
|
2011-11-28 22:41:58 -05:00
|
|
|
setkeybinding(MODKEY, XK_Up, kf_ws_next_all, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_Down, kf_ws_prev_all, NULL);
|
2010-07-01 19:01:15 +00:00
|
|
|
setkeybinding(MODKEY, XK_a, kf_ws_prior, NULL);
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_Right, kf_screen_next, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_Left, kf_screen_prev, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_1, kf_mvws_1, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_2, kf_mvws_2, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_3, kf_mvws_3, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_4, kf_mvws_4, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_5, kf_mvws_5, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_6, kf_mvws_6, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_7, kf_mvws_7, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_8, kf_mvws_8, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_9, kf_mvws_9, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_0, kf_mvws_10, NULL);
|
2012-04-08 01:59:41 +08:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F1, kf_mvws_11, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F2, kf_mvws_12, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F3, kf_mvws_13, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F4, kf_mvws_14, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F5, kf_mvws_15, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F6, kf_mvws_16, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F7, kf_mvws_17, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F8, kf_mvws_18, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F9, kf_mvws_19, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F10, kf_mvws_20, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F11, kf_mvws_21, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_F12, kf_mvws_22, NULL);
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY, XK_b, kf_bar_toggle, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_Tab, kf_focus_next, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_Tab, kf_focus_prev, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_x, kf_wind_kill, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_x, kf_wind_del, NULL);
|
2011-10-03 16:39:12 -05:00
|
|
|
setkeybinding(MODKEY, XK_s, kf_spawn_custom,"screenshot_all");
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_s, kf_spawn_custom,"screenshot_wind");
|
2009-09-12 21:32:21 +00:00
|
|
|
setkeybinding(MODKEY, XK_t, kf_float_toggle,NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_v, kf_version, NULL);
|
2011-10-03 16:39:12 -05:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_Delete, kf_spawn_custom,"lock");
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_i, kf_spawn_custom,"initscr");
|
2011-06-06 19:52:03 +00:00
|
|
|
setkeybinding(MODKEY, XK_w, kf_iconify, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_w, kf_uniconify, NULL);
|
2011-06-24 16:53:40 +00:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_r, kf_raise_toggle,NULL);
|
2011-08-08 22:41:51 +00:00
|
|
|
setkeybinding(MODKEY, XK_v, kf_button2, NULL);
|
2011-10-03 16:39:12 -05:00
|
|
|
setkeybinding(MODKEY, XK_equal, kf_width_grow, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_minus, kf_width_shrink,NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_equal, kf_height_grow, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_minus, kf_height_shrink,NULL);
|
|
|
|
setkeybinding(MODKEY, XK_bracketleft, kf_move_left, NULL);
|
|
|
|
setkeybinding(MODKEY, XK_bracketright,kf_move_right, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_bracketleft, kf_move_up, NULL);
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_bracketright,kf_move_down, NULL);
|
2011-11-28 23:25:46 -05:00
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_slash, kf_name_workspace,NULL);
|
|
|
|
setkeybinding(MODKEY, XK_slash, kf_search_workspace,NULL);
|
2011-11-29 21:49:27 -05:00
|
|
|
setkeybinding(MODKEY, XK_f, kf_search_win, NULL);
|
2009-10-13 02:28:47 +00:00
|
|
|
#ifdef SWM_DEBUG
|
|
|
|
setkeybinding(MODKEY|ShiftMask, XK_d, kf_dumpwins, NULL);
|
|
|
|
#endif
|
2009-03-10 01:32:06 +00:00
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2011-10-25 22:40:12 -04:00
|
|
|
void
|
|
|
|
clear_keys(void)
|
|
|
|
{
|
2012-02-09 17:19:00 +00:00
|
|
|
struct key *kp;
|
2011-10-25 22:40:12 -04:00
|
|
|
|
2012-02-09 17:19:00 +00:00
|
|
|
while (RB_EMPTY(&keys) == 0) {
|
|
|
|
kp = RB_ROOT(&keys);
|
|
|
|
key_remove(kp);
|
2012-02-02 21:19:17 +00:00
|
|
|
}
|
2011-10-25 22:40:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setkeymapping(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
char keymapping_file[PATH_MAX];
|
|
|
|
DNPRINTF(SWM_D_KEY, "setkeymapping: enter\n");
|
|
|
|
if (value[0] == '~')
|
|
|
|
snprintf(keymapping_file, sizeof keymapping_file, "%s/%s",
|
|
|
|
pwd->pw_dir, &value[1]);
|
|
|
|
else
|
|
|
|
strlcpy(keymapping_file, value, sizeof keymapping_file);
|
|
|
|
clear_keys();
|
|
|
|
/* load new key bindings; if it fails, revert to default bindings */
|
|
|
|
if (conf_load(keymapping_file, SWM_CONF_KEYMAPPING)) {
|
|
|
|
clear_keys();
|
|
|
|
setup_keys();
|
|
|
|
}
|
|
|
|
DNPRINTF(SWM_D_KEY, "setkeymapping: leave\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
|
|
|
updatenumlockmask(void)
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
XModifierKeymap *modmap;
|
|
|
|
|
2009-01-13 22:51:20 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "updatenumlockmask\n");
|
2009-01-13 15:55:13 +00:00
|
|
|
numlockmask = 0;
|
|
|
|
modmap = XGetModifierMapping(display);
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
for (j = 0; j < modmap->max_keypermod; j++)
|
|
|
|
if (modmap->modifiermap[i * modmap->max_keypermod + j]
|
2011-06-14 22:20:55 +00:00
|
|
|
== XKeysymToKeycode(display, XK_Num_Lock))
|
2009-01-13 15:55:13 +00:00
|
|
|
numlockmask = (1 << i);
|
|
|
|
|
|
|
|
XFreeModifiermap(modmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grabkeys(void)
|
|
|
|
{
|
2012-02-02 21:19:17 +00:00
|
|
|
unsigned int j, k;
|
2009-01-13 15:55:13 +00:00
|
|
|
KeyCode code;
|
|
|
|
unsigned int modifiers[] =
|
|
|
|
{ 0, LockMask, numlockmask, numlockmask | LockMask };
|
2012-02-02 21:19:17 +00:00
|
|
|
struct key *kp;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-01-13 22:51:20 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "grabkeys\n");
|
2009-01-13 15:55:13 +00:00
|
|
|
updatenumlockmask();
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
for (k = 0; k < ScreenCount(display); k++) {
|
|
|
|
if (TAILQ_EMPTY(&screens[k].rl))
|
|
|
|
continue;
|
|
|
|
XUngrabKey(display, AnyKey, AnyModifier, screens[k].root);
|
2012-05-24 21:41:58 +01:00
|
|
|
RB_FOREACH(kp, key_tree, &keys) {
|
2012-02-02 21:19:17 +00:00
|
|
|
if ((code = XKeysymToKeycode(display, kp->keysym)))
|
2009-01-19 19:27:36 +00:00
|
|
|
for (j = 0; j < LENGTH(modifiers); j++)
|
2009-01-19 05:48:11 +00:00
|
|
|
XGrabKey(display, code,
|
2012-02-02 21:19:17 +00:00
|
|
|
kp->mod | modifiers[j],
|
2009-01-19 05:48:11 +00:00
|
|
|
screens[k].root, True,
|
|
|
|
GrabModeAsync, GrabModeAsync);
|
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-22 03:46:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
grabbuttons(struct ws_win *win, int focused)
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
unsigned int modifiers[] =
|
|
|
|
{ 0, LockMask, numlockmask, numlockmask|LockMask };
|
|
|
|
|
|
|
|
updatenumlockmask();
|
|
|
|
XUngrabButton(display, AnyButton, AnyModifier, win->id);
|
2010-09-16 02:26:45 +00:00
|
|
|
if (focused) {
|
2009-01-22 03:46:13 +00:00
|
|
|
for (i = 0; i < LENGTH(buttons); i++)
|
|
|
|
if (buttons[i].action == client_click)
|
|
|
|
for (j = 0; j < LENGTH(modifiers); j++)
|
|
|
|
XGrabButton(display, buttons[i].button,
|
|
|
|
buttons[i].mask | modifiers[j],
|
|
|
|
win->id, False, BUTTONMASK,
|
|
|
|
GrabModeAsync, GrabModeSync, None,
|
|
|
|
None);
|
|
|
|
} else
|
|
|
|
XGrabButton(display, AnyButton, AnyModifier, win->id, False,
|
|
|
|
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
}
|
|
|
|
|
2009-05-25 22:04:56 +00:00
|
|
|
const char *quirkname[] = {
|
|
|
|
"NONE", /* config string for "no value" */
|
|
|
|
"FLOAT",
|
|
|
|
"TRANSSZ",
|
|
|
|
"ANYWHERE",
|
|
|
|
"XTERM_FONTADJ",
|
|
|
|
"FULLSCREEN",
|
2011-06-14 15:47:57 +00:00
|
|
|
"FOCUSPREV",
|
2009-05-25 22:04:56 +00:00
|
|
|
};
|
|
|
|
|
2009-08-11 16:43:30 +00:00
|
|
|
/* SWM_Q_WS: retain '|' for back compat for now (2009-08-11) */
|
|
|
|
#define SWM_Q_WS "\n|+ \t"
|
2009-05-25 22:04:56 +00:00
|
|
|
int
|
|
|
|
parsequirks(char *qstr, unsigned long *quirk)
|
|
|
|
{
|
|
|
|
char *cp, *name;
|
|
|
|
int i;
|
2009-10-02 03:28:46 +00:00
|
|
|
|
2009-05-25 22:04:56 +00:00
|
|
|
if (quirk == NULL)
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
2009-10-02 03:28:46 +00:00
|
|
|
|
2009-05-25 22:04:56 +00:00
|
|
|
cp = qstr;
|
|
|
|
*quirk = 0;
|
|
|
|
while ((name = strsep(&cp, SWM_Q_WS)) != NULL) {
|
|
|
|
if (cp)
|
|
|
|
cp += (long)strspn(cp, SWM_Q_WS);
|
|
|
|
for (i = 0; i < LENGTH(quirkname); i++) {
|
|
|
|
if (!strncasecmp(name, quirkname[i], SWM_QUIRK_LEN)) {
|
2011-06-14 22:20:55 +00:00
|
|
|
DNPRINTF(SWM_D_QUIRK,
|
|
|
|
"parsequirks: %s\n", name);
|
2009-05-25 22:04:56 +00:00
|
|
|
if (i == 0) {
|
|
|
|
*quirk = 0;
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
|
|
|
*quirk |= 1 << (i-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= LENGTH(quirkname)) {
|
|
|
|
DNPRINTF(SWM_D_QUIRK,
|
|
|
|
"parsequirks: invalid quirk [%s]\n", name);
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-05-25 22:04:56 +00:00
|
|
|
void
|
2012-02-02 21:44:21 +00:00
|
|
|
quirk_insert(const char *class, const char *name, unsigned long quirk)
|
2009-05-25 22:04:56 +00:00
|
|
|
{
|
2012-02-02 23:25:29 +00:00
|
|
|
struct quirk *qp;
|
2009-10-02 03:28:46 +00:00
|
|
|
|
2012-02-02 21:44:21 +00:00
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_insert: %s:%s [%lu]\n", class, name,
|
|
|
|
quirk);
|
|
|
|
|
|
|
|
if ((qp = malloc(sizeof *qp)) == NULL)
|
|
|
|
err(1, "quirk_insert: malloc");
|
|
|
|
if ((qp->class = strdup(class)) == NULL)
|
|
|
|
err(1, "quirk_insert: strdup");
|
|
|
|
if ((qp->name = strdup(name)) == NULL)
|
|
|
|
err(1, "quirk_insert: strdup");
|
|
|
|
|
|
|
|
qp->quirk = quirk;
|
|
|
|
TAILQ_INSERT_TAIL(&quirks, qp, entry);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_insert: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
quirk_remove(struct quirk *qp)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_remove: %s:%s [%lu]\n", qp->class,
|
|
|
|
qp->name, qp->quirk);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&quirks, qp, entry);
|
|
|
|
free(qp->class);
|
|
|
|
free(qp->name);
|
|
|
|
free(qp);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_remove: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
quirk_replace(struct quirk *qp, const char *class, const char *name,
|
|
|
|
unsigned long quirk)
|
|
|
|
{
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_replace: %s:%s [%lu]\n", qp->class,
|
|
|
|
qp->name, qp->quirk);
|
|
|
|
|
|
|
|
quirk_remove(qp);
|
|
|
|
quirk_insert(class, name, quirk);
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "quirk_replace: leave\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setquirk(const char *class, const char *name, unsigned long quirk)
|
|
|
|
{
|
2012-02-02 23:25:29 +00:00
|
|
|
struct quirk *qp;
|
2012-02-02 21:44:21 +00:00
|
|
|
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "setquirk: enter %s:%s [%lu]\n", class, name,
|
2012-02-03 08:01:09 -06:00
|
|
|
quirk);
|
2012-02-02 21:44:21 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(qp, &quirks, entry) {
|
|
|
|
if (!strcmp(qp->class, class) && !strcmp(qp->name, name)) {
|
|
|
|
if (!quirk)
|
|
|
|
quirk_remove(qp);
|
|
|
|
else
|
|
|
|
quirk_replace(qp, class, name, quirk);
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "setquirk: leave\n");
|
|
|
|
return;
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!quirk) {
|
2012-02-02 21:44:21 +00:00
|
|
|
warnx("error: setquirk: cannot find class/name combination");
|
2009-05-25 22:04:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-02 21:44:21 +00:00
|
|
|
|
|
|
|
quirk_insert(class, name, quirk);
|
|
|
|
DNPRINTF(SWM_D_QUIRK, "setquirk: leave\n");
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
int
|
|
|
|
setconfquirk(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
char *cp, *class, *name;
|
|
|
|
int retval;
|
|
|
|
unsigned long quirks;
|
|
|
|
if (selector == NULL)
|
|
|
|
return (0);
|
|
|
|
if ((cp = strchr(selector, ':')) == NULL)
|
|
|
|
return (0);
|
|
|
|
*cp = '\0';
|
|
|
|
class = selector;
|
|
|
|
name = cp + 1;
|
2009-09-12 21:32:21 +00:00
|
|
|
if ((retval = parsequirks(value, &quirks)) == 0)
|
2009-08-11 16:20:55 +00:00
|
|
|
setquirk(class, name, quirks);
|
|
|
|
return (retval);
|
|
|
|
}
|
2009-05-25 22:04:56 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
setup_quirks(void)
|
|
|
|
{
|
2011-06-13 20:28:04 +00:00
|
|
|
setquirk("MPlayer", "xv", SWM_Q_FLOAT | SWM_Q_FULLSCREEN | SWM_Q_FOCUSPREV);
|
2010-07-01 02:01:04 +00:00
|
|
|
setquirk("OpenOffice.org 3.2", "VCLSalFrame", SWM_Q_FLOAT);
|
2009-05-25 22:04:56 +00:00
|
|
|
setquirk("Firefox-bin", "firefox-bin", SWM_Q_TRANSSZ);
|
|
|
|
setquirk("Firefox", "Dialog", SWM_Q_FLOAT);
|
|
|
|
setquirk("Gimp", "gimp", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
|
|
|
|
setquirk("XTerm", "xterm", SWM_Q_XTERM_FONTADJ);
|
|
|
|
setquirk("xine", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
|
|
|
|
setquirk("Xitk", "Xitk Combo", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
|
|
|
|
setquirk("xine", "xine Panel", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
|
|
|
|
setquirk("Xitk", "Xine Window", SWM_Q_FLOAT | SWM_Q_ANYWHERE);
|
|
|
|
setquirk("xine", "xine Video Fullscreen Window", SWM_Q_FULLSCREEN | SWM_Q_FLOAT);
|
|
|
|
setquirk("pcb", "pcb", SWM_Q_FLOAT);
|
2011-06-09 21:26:38 +00:00
|
|
|
setquirk("SDL_App", "SDL_App", SWM_Q_FLOAT | SWM_Q_FULLSCREEN);
|
2009-05-25 22:04:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
/* conf file stuff */
|
2012-02-15 14:09:13 -06:00
|
|
|
#define SWM_CONF_FILE "spectrwm.conf"
|
|
|
|
#define SWM_CONF_FILE_OLD "scrotwm.conf"
|
2009-08-11 16:20:55 +00:00
|
|
|
|
2011-06-14 22:20:55 +00:00
|
|
|
enum { SWM_S_BAR_DELAY, SWM_S_BAR_ENABLED, SWM_S_BAR_BORDER_WIDTH,
|
|
|
|
SWM_S_STACK_ENABLED, SWM_S_CLOCK_ENABLED, SWM_S_CLOCK_FORMAT,
|
2012-04-08 01:59:41 +08:00
|
|
|
SWM_S_CYCLE_EMPTY, SWM_S_CYCLE_VISIBLE, SWM_S_WORKSPACE_LIMIT,
|
|
|
|
SWM_S_SS_ENABLED, SWM_S_TERM_WIDTH, SWM_S_TITLE_CLASS_ENABLED,
|
2012-05-23 18:31:11 +08:00
|
|
|
SWM_S_TITLE_NAME_ENABLED, SWM_S_WINDOW_NAME_ENABLED,
|
|
|
|
SWM_S_URGENT_ENABLED, SWM_S_FOCUS_MODE, SWM_S_FOCUS_CLOSE,
|
|
|
|
SWM_S_FOCUS_CLOSE_WRAP, SWM_S_FOCUS_DEFAULT, SWM_S_SPAWN_ORDER,
|
|
|
|
SWM_S_DISABLE_BORDER, SWM_S_BORDER_WIDTH, SWM_S_BAR_FONT,
|
|
|
|
SWM_S_BAR_ACTION, SWM_S_SPAWN_TERM, SWM_S_SS_APP, SWM_S_DIALOG_RATIO,
|
2012-05-13 01:33:38 +01:00
|
|
|
SWM_S_BAR_AT_BOTTOM, SWM_S_VERBOSE_LAYOUT, SWM_S_BAR_JUSTIFY,
|
|
|
|
SWM_S_BAR_FORMAT
|
2010-01-13 21:48:35 +00:00
|
|
|
};
|
2009-08-11 16:20:55 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
setconfvalue(char *selector, char *value, int flags)
|
|
|
|
{
|
2011-11-17 19:55:05 -06:00
|
|
|
int i;
|
2012-02-02 07:00:45 +08:00
|
|
|
char *b;
|
2011-11-17 19:55:05 -06:00
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
switch (flags) {
|
|
|
|
case SWM_S_BAR_DELAY:
|
|
|
|
bar_delay = atoi(value);
|
|
|
|
break;
|
|
|
|
case SWM_S_BAR_ENABLED:
|
|
|
|
bar_enabled = atoi(value);
|
|
|
|
break;
|
2011-03-11 21:34:19 +00:00
|
|
|
case SWM_S_BAR_BORDER_WIDTH:
|
|
|
|
bar_border_width = atoi(value);
|
|
|
|
break;
|
2010-07-15 14:03:04 +00:00
|
|
|
case SWM_S_BAR_AT_BOTTOM:
|
|
|
|
bar_at_bottom = atoi(value);
|
|
|
|
break;
|
2011-11-28 22:31:11 -05:00
|
|
|
case SWM_S_BAR_JUSTIFY:
|
|
|
|
if (!strcmp(value, "left"))
|
|
|
|
bar_justify = SWM_BAR_JUSTIFY_LEFT;
|
|
|
|
else if (!strcmp(value, "center"))
|
|
|
|
bar_justify = SWM_BAR_JUSTIFY_CENTER;
|
|
|
|
else if (!strcmp(value, "right"))
|
|
|
|
bar_justify = SWM_BAR_JUSTIFY_RIGHT;
|
|
|
|
else
|
|
|
|
errx(1, "invalid bar_justify");
|
|
|
|
break;
|
2012-05-13 01:33:38 +01:00
|
|
|
case SWM_S_BAR_FORMAT:
|
|
|
|
free(bar_format);
|
|
|
|
if ((bar_format = strdup(value)) == NULL)
|
|
|
|
err(1, "setconfvalue: bar_format");
|
|
|
|
break;
|
2009-10-02 19:50:05 +00:00
|
|
|
case SWM_S_STACK_ENABLED:
|
|
|
|
stack_enabled = atoi(value);
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
case SWM_S_CLOCK_ENABLED:
|
|
|
|
clock_enabled = atoi(value);
|
|
|
|
break;
|
2010-01-13 21:48:35 +00:00
|
|
|
case SWM_S_CLOCK_FORMAT:
|
|
|
|
#ifndef SWM_DENY_CLOCK_FORMAT
|
|
|
|
free(clock_format);
|
|
|
|
if ((clock_format = strdup(value)) == NULL)
|
|
|
|
err(1, "setconfvalue: clock_format");
|
|
|
|
#endif
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
case SWM_S_CYCLE_EMPTY:
|
|
|
|
cycle_empty = atoi(value);
|
|
|
|
break;
|
|
|
|
case SWM_S_CYCLE_VISIBLE:
|
|
|
|
cycle_visible = atoi(value);
|
|
|
|
break;
|
2012-04-08 01:59:41 +08:00
|
|
|
case SWM_S_WORKSPACE_LIMIT:
|
|
|
|
workspace_limit = atoi(value);
|
|
|
|
if (workspace_limit > SWM_WS_MAX)
|
|
|
|
workspace_limit = SWM_WS_MAX;
|
|
|
|
else if (workspace_limit < 1)
|
|
|
|
workspace_limit = 1;
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
case SWM_S_SS_ENABLED:
|
|
|
|
ss_enabled = atoi(value);
|
|
|
|
break;
|
|
|
|
case SWM_S_TERM_WIDTH:
|
|
|
|
term_width = atoi(value);
|
|
|
|
break;
|
|
|
|
case SWM_S_TITLE_CLASS_ENABLED:
|
|
|
|
title_class_enabled = atoi(value);
|
|
|
|
break;
|
2011-01-18 19:43:12 +00:00
|
|
|
case SWM_S_WINDOW_NAME_ENABLED:
|
|
|
|
window_name_enabled = atoi(value);
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
case SWM_S_TITLE_NAME_ENABLED:
|
|
|
|
title_name_enabled = atoi(value);
|
|
|
|
break;
|
2011-08-06 18:21:00 +00:00
|
|
|
case SWM_S_URGENT_ENABLED:
|
|
|
|
urgent_enabled = atoi(value);
|
|
|
|
break;
|
2010-06-30 00:09:19 +00:00
|
|
|
case SWM_S_FOCUS_MODE:
|
|
|
|
if (!strcmp(value, "default"))
|
|
|
|
focus_mode = SWM_FOCUS_DEFAULT;
|
|
|
|
else if (!strcmp(value, "follow_cursor"))
|
|
|
|
focus_mode = SWM_FOCUS_FOLLOW;
|
|
|
|
else if (!strcmp(value, "synergy"))
|
|
|
|
focus_mode = SWM_FOCUS_SYNERGY;
|
|
|
|
else
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "focus_mode");
|
2010-06-30 00:09:19 +00:00
|
|
|
break;
|
2012-05-23 18:31:11 +08:00
|
|
|
case SWM_S_FOCUS_CLOSE:
|
|
|
|
if (!strcmp(value, "first"))
|
|
|
|
focus_close = SWM_STACK_BOTTOM;
|
|
|
|
else if (!strcmp(value, "last"))
|
|
|
|
focus_close = SWM_STACK_TOP;
|
|
|
|
else if (!strcmp(value, "next"))
|
|
|
|
focus_close = SWM_STACK_ABOVE;
|
|
|
|
else if (!strcmp(value, "previous"))
|
|
|
|
focus_close = SWM_STACK_BELOW;
|
|
|
|
else
|
|
|
|
errx(1, "focus_close");
|
|
|
|
break;
|
|
|
|
case SWM_S_FOCUS_CLOSE_WRAP:
|
|
|
|
focus_close_wrap = atoi(value);
|
|
|
|
break;
|
|
|
|
case SWM_S_FOCUS_DEFAULT:
|
|
|
|
if (!strcmp(value, "last"))
|
|
|
|
focus_default = SWM_STACK_TOP;
|
|
|
|
else if (!strcmp(value, "first"))
|
|
|
|
focus_default = SWM_STACK_BOTTOM;
|
|
|
|
else
|
|
|
|
errx(1, "focus_default");
|
|
|
|
break;
|
|
|
|
case SWM_S_SPAWN_ORDER:
|
|
|
|
if (!strcmp(value, "first"))
|
|
|
|
spawn_position = SWM_STACK_BOTTOM;
|
|
|
|
else if (!strcmp(value, "last"))
|
|
|
|
spawn_position = SWM_STACK_TOP;
|
|
|
|
else if (!strcmp(value, "next"))
|
|
|
|
spawn_position = SWM_STACK_ABOVE;
|
|
|
|
else if (!strcmp(value, "previous"))
|
|
|
|
spawn_position = SWM_STACK_BELOW;
|
|
|
|
else
|
|
|
|
errx(1, "spawn_position");
|
|
|
|
break;
|
2010-07-01 23:44:16 +00:00
|
|
|
case SWM_S_DISABLE_BORDER:
|
|
|
|
disable_border = atoi(value);
|
|
|
|
break;
|
2011-03-11 14:12:49 +00:00
|
|
|
case SWM_S_BORDER_WIDTH:
|
|
|
|
border_width = atoi(value);
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
case SWM_S_BAR_FONT:
|
2012-02-02 07:00:45 +08:00
|
|
|
b = bar_fonts;
|
|
|
|
if (asprintf(&bar_fonts, "%s,%s", value, bar_fonts) == -1)
|
|
|
|
err(1, "setconfvalue: asprintf: failed to allocate "
|
|
|
|
"memory for bar_fonts.");
|
|
|
|
|
|
|
|
free(b);
|
2009-08-11 16:20:55 +00:00
|
|
|
break;
|
|
|
|
case SWM_S_BAR_ACTION:
|
2009-09-12 21:32:21 +00:00
|
|
|
free(bar_argv[0]);
|
|
|
|
if ((bar_argv[0] = strdup(value)) == NULL)
|
|
|
|
err(1, "setconfvalue: bar_action");
|
2009-08-11 16:20:55 +00:00
|
|
|
break;
|
|
|
|
case SWM_S_SPAWN_TERM:
|
2009-09-12 21:32:21 +00:00
|
|
|
free(spawn_term[0]);
|
|
|
|
if ((spawn_term[0] = strdup(value)) == NULL)
|
|
|
|
err(1, "setconfvalue: spawn_term");
|
2009-08-11 16:20:55 +00:00
|
|
|
break;
|
|
|
|
case SWM_S_SS_APP:
|
|
|
|
break;
|
|
|
|
case SWM_S_DIALOG_RATIO:
|
|
|
|
dialog_ratio = atof(value);
|
|
|
|
if (dialog_ratio > 1.0 || dialog_ratio <= .3)
|
|
|
|
dialog_ratio = .6;
|
|
|
|
break;
|
2011-07-19 21:28:15 +00:00
|
|
|
case SWM_S_VERBOSE_LAYOUT:
|
|
|
|
verbose_layout = atoi(value);
|
2011-08-06 18:21:00 +00:00
|
|
|
for (i = 0; layouts[i].l_stack != NULL; i++) {
|
2011-07-19 21:28:15 +00:00
|
|
|
if (verbose_layout)
|
|
|
|
layouts[i].l_string = fancy_stacker;
|
|
|
|
else
|
|
|
|
layouts[i].l_string = plain_stacker;
|
|
|
|
}
|
|
|
|
break;
|
2009-08-11 16:20:55 +00:00
|
|
|
default:
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setconfmodkey(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
if (!strncasecmp(value, "Mod1", strlen("Mod1")))
|
|
|
|
update_modkey(Mod1Mask);
|
|
|
|
else if (!strncasecmp(value, "Mod2", strlen("Mod2")))
|
|
|
|
update_modkey(Mod2Mask);
|
|
|
|
else if (!strncasecmp(value, "Mod3", strlen("Mod3")))
|
|
|
|
update_modkey(Mod3Mask);
|
|
|
|
else if (!strncasecmp(value, "Mod4", strlen("Mod4")))
|
|
|
|
update_modkey(Mod4Mask);
|
|
|
|
else
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
|
|
|
return (0);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setconfcolor(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
setscreencolor(value, ((selector == NULL)?-1:atoi(selector)), flags);
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
setconfregion(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
custom_region(value);
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
int
|
|
|
|
setautorun(char *selector, char *value, int flags)
|
|
|
|
{
|
|
|
|
int ws_id;
|
|
|
|
char s[1024];
|
2011-06-23 16:31:54 +00:00
|
|
|
char *ap, *sp = s;
|
2011-06-23 02:15:53 +00:00
|
|
|
union arg a;
|
2011-06-23 16:31:54 +00:00
|
|
|
int argc = 0;
|
2011-06-23 02:15:53 +00:00
|
|
|
long pid;
|
|
|
|
struct pid_e *p;
|
|
|
|
|
|
|
|
if (getenv("SWM_STARTED"))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bzero(s, sizeof s);
|
2011-06-23 16:31:54 +00:00
|
|
|
if (sscanf(value, "ws[%d]:%1023c", &ws_id, s) != 2)
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "invalid autorun entry, should be 'ws[<idx>]:command'");
|
2011-06-23 02:15:53 +00:00
|
|
|
ws_id--;
|
2012-04-08 01:59:41 +08:00
|
|
|
if (ws_id < 0 || ws_id >= workspace_limit)
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "autorun: invalid workspace %d", ws_id + 1);
|
2011-06-23 02:15:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a little intricate
|
|
|
|
*
|
|
|
|
* If the pid already exists we simply reuse it because it means it was
|
|
|
|
* used before AND not claimed by manage_window. We get away with
|
|
|
|
* altering it in the parent after INSERT because this can not be a race
|
|
|
|
*/
|
2011-06-23 16:31:54 +00:00
|
|
|
a.argv = NULL;
|
|
|
|
while ((ap = strsep(&sp, " \t")) != NULL) {
|
|
|
|
if (*ap == '\0')
|
|
|
|
continue;
|
|
|
|
DNPRINTF(SWM_D_SPAWN, "setautorun: arg [%s]\n", ap);
|
|
|
|
argc++;
|
|
|
|
if ((a.argv = realloc(a.argv, argc * sizeof(char *))) == NULL)
|
|
|
|
err(1, "setautorun: realloc");
|
|
|
|
a.argv[argc - 1] = ap;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((a.argv = realloc(a.argv, (argc + 1) * sizeof(char *))) == NULL)
|
|
|
|
err(1, "setautorun: realloc");
|
|
|
|
a.argv[argc] = NULL;
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
if ((pid = fork()) == 0) {
|
|
|
|
spawn(ws_id, &a, 1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
_exit(1);
|
|
|
|
}
|
2011-06-23 16:31:54 +00:00
|
|
|
free(a.argv);
|
2011-06-23 02:15:53 +00:00
|
|
|
|
|
|
|
/* parent */
|
|
|
|
p = find_pid(pid);
|
|
|
|
if (p == NULL) {
|
|
|
|
p = calloc(1, sizeof *p);
|
|
|
|
if (p == NULL)
|
|
|
|
return (1);
|
|
|
|
TAILQ_INSERT_TAIL(&pidlist, p, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
p->pid = pid;
|
|
|
|
p->ws = ws_id;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-06-23 17:52:39 +00:00
|
|
|
int
|
|
|
|
setlayout(char *selector, char *value, int flags)
|
|
|
|
{
|
2011-10-25 15:19:02 -05:00
|
|
|
int ws_id, i, x, mg, ma, si, raise;
|
|
|
|
int st = SWM_V_STACK;
|
2011-06-23 17:52:39 +00:00
|
|
|
char s[1024];
|
|
|
|
struct workspace *ws;
|
|
|
|
|
|
|
|
if (getenv("SWM_STARTED"))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bzero(s, sizeof s);
|
2011-06-24 16:53:40 +00:00
|
|
|
if (sscanf(value, "ws[%d]:%d:%d:%d:%d:%1023c",
|
|
|
|
&ws_id, &mg, &ma, &si, &raise, s) != 6)
|
|
|
|
errx(1, "invalid layout entry, should be 'ws[<idx>]:"
|
|
|
|
"<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
|
2011-12-07 21:53:12 -05:00
|
|
|
"<type>'");
|
2011-06-23 17:52:39 +00:00
|
|
|
ws_id--;
|
2012-04-08 01:59:41 +08:00
|
|
|
if (ws_id < 0 || ws_id >= workspace_limit)
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "layout: invalid workspace %d", ws_id + 1);
|
2011-06-23 17:52:39 +00:00
|
|
|
|
|
|
|
if (!strcasecmp(s, "vertical"))
|
|
|
|
st = SWM_V_STACK;
|
|
|
|
else if (!strcasecmp(s, "horizontal"))
|
|
|
|
st = SWM_H_STACK;
|
|
|
|
else if (!strcasecmp(s, "fullscreen"))
|
|
|
|
st = SWM_MAX_STACK;
|
|
|
|
else
|
2011-06-24 16:53:40 +00:00
|
|
|
errx(1, "invalid layout entry, should be 'ws[<idx>]:"
|
|
|
|
"<master_grow>:<master_add>:<stack_inc>:<always_raise>:"
|
2011-12-07 21:53:12 -05:00
|
|
|
"<type>'");
|
2011-06-23 17:52:39 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
ws = (struct workspace *)&screens[i].ws;
|
|
|
|
ws[ws_id].cur_layout = &layouts[st];
|
2011-06-24 16:53:40 +00:00
|
|
|
|
|
|
|
ws[ws_id].always_raise = raise;
|
2011-06-23 18:56:39 +00:00
|
|
|
if (st == SWM_MAX_STACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* master grow */
|
|
|
|
for (x = 0; x < abs(mg); x++) {
|
|
|
|
ws[ws_id].cur_layout->l_config(&ws[ws_id],
|
|
|
|
mg >= 0 ? SWM_ARG_ID_MASTERGROW :
|
|
|
|
SWM_ARG_ID_MASTERSHRINK);
|
|
|
|
stack();
|
|
|
|
}
|
|
|
|
/* master add */
|
|
|
|
for (x = 0; x < abs(ma); x++) {
|
|
|
|
ws[ws_id].cur_layout->l_config(&ws[ws_id],
|
|
|
|
ma >= 0 ? SWM_ARG_ID_MASTERADD :
|
|
|
|
SWM_ARG_ID_MASTERDEL);
|
|
|
|
stack();
|
|
|
|
}
|
|
|
|
/* stack inc */
|
|
|
|
for (x = 0; x < abs(si); x++) {
|
|
|
|
ws[ws_id].cur_layout->l_config(&ws[ws_id],
|
|
|
|
si >= 0 ? SWM_ARG_ID_STACKINC :
|
|
|
|
SWM_ARG_ID_STACKDEC);
|
|
|
|
stack();
|
|
|
|
}
|
2011-06-23 17:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
/* config options */
|
|
|
|
struct config_option {
|
|
|
|
char *optname;
|
2011-06-23 17:52:39 +00:00
|
|
|
int (*func)(char*, char*, int);
|
|
|
|
int funcflags;
|
2009-08-11 16:20:55 +00:00
|
|
|
};
|
|
|
|
struct config_option configopt[] = {
|
|
|
|
{ "bar_enabled", setconfvalue, SWM_S_BAR_ENABLED },
|
2010-07-15 14:03:04 +00:00
|
|
|
{ "bar_at_bottom", setconfvalue, SWM_S_BAR_AT_BOTTOM },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "bar_border", setconfcolor, SWM_S_COLOR_BAR_BORDER },
|
2011-06-23 02:15:53 +00:00
|
|
|
{ "bar_border_width", setconfvalue, SWM_S_BAR_BORDER_WIDTH },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "bar_color", setconfcolor, SWM_S_COLOR_BAR },
|
|
|
|
{ "bar_font_color", setconfcolor, SWM_S_COLOR_BAR_FONT },
|
|
|
|
{ "bar_font", setconfvalue, SWM_S_BAR_FONT },
|
|
|
|
{ "bar_action", setconfvalue, SWM_S_BAR_ACTION },
|
|
|
|
{ "bar_delay", setconfvalue, SWM_S_BAR_DELAY },
|
2011-11-28 22:31:11 -05:00
|
|
|
{ "bar_justify", setconfvalue, SWM_S_BAR_JUSTIFY },
|
2012-05-13 01:33:38 +01:00
|
|
|
{ "bar_format", setconfvalue, SWM_S_BAR_FORMAT },
|
2011-10-25 22:40:12 -04:00
|
|
|
{ "keyboard_mapping", setkeymapping, 0 },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "bind", setconfbinding, 0 },
|
2009-10-02 19:50:05 +00:00
|
|
|
{ "stack_enabled", setconfvalue, SWM_S_STACK_ENABLED },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "clock_enabled", setconfvalue, SWM_S_CLOCK_ENABLED },
|
2010-01-13 21:48:35 +00:00
|
|
|
{ "clock_format", setconfvalue, SWM_S_CLOCK_FORMAT },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "color_focus", setconfcolor, SWM_S_COLOR_FOCUS },
|
|
|
|
{ "color_unfocus", setconfcolor, SWM_S_COLOR_UNFOCUS },
|
|
|
|
{ "cycle_empty", setconfvalue, SWM_S_CYCLE_EMPTY },
|
|
|
|
{ "cycle_visible", setconfvalue, SWM_S_CYCLE_VISIBLE },
|
2012-04-08 01:59:41 +08:00
|
|
|
{ "workspace_limit", setconfvalue, SWM_S_WORKSPACE_LIMIT },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "dialog_ratio", setconfvalue, SWM_S_DIALOG_RATIO },
|
2011-07-19 21:28:15 +00:00
|
|
|
{ "verbose_layout", setconfvalue, SWM_S_VERBOSE_LAYOUT },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "modkey", setconfmodkey, 0 },
|
2009-09-12 21:32:21 +00:00
|
|
|
{ "program", setconfspawn, 0 },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "quirk", setconfquirk, 0 },
|
|
|
|
{ "region", setconfregion, 0 },
|
|
|
|
{ "spawn_term", setconfvalue, SWM_S_SPAWN_TERM },
|
|
|
|
{ "screenshot_enabled", setconfvalue, SWM_S_SS_ENABLED },
|
|
|
|
{ "screenshot_app", setconfvalue, SWM_S_SS_APP },
|
2011-01-18 19:43:12 +00:00
|
|
|
{ "window_name_enabled", setconfvalue, SWM_S_WINDOW_NAME_ENABLED },
|
2011-08-06 18:21:00 +00:00
|
|
|
{ "urgent_enabled", setconfvalue, SWM_S_URGENT_ENABLED },
|
2009-08-11 16:20:55 +00:00
|
|
|
{ "term_width", setconfvalue, SWM_S_TERM_WIDTH },
|
|
|
|
{ "title_class_enabled", setconfvalue, SWM_S_TITLE_CLASS_ENABLED },
|
2010-06-30 00:09:19 +00:00
|
|
|
{ "title_name_enabled", setconfvalue, SWM_S_TITLE_NAME_ENABLED },
|
2011-06-23 02:15:53 +00:00
|
|
|
{ "focus_mode", setconfvalue, SWM_S_FOCUS_MODE },
|
2012-05-23 18:31:11 +08:00
|
|
|
{ "focus_close", setconfvalue, SWM_S_FOCUS_CLOSE },
|
|
|
|
{ "focus_close_wrap", setconfvalue, SWM_S_FOCUS_CLOSE_WRAP },
|
|
|
|
{ "focus_default", setconfvalue, SWM_S_FOCUS_DEFAULT },
|
|
|
|
{ "spawn_position", setconfvalue, SWM_S_SPAWN_ORDER },
|
2011-06-23 02:15:53 +00:00
|
|
|
{ "disable_border", setconfvalue, SWM_S_DISABLE_BORDER },
|
|
|
|
{ "border_width", setconfvalue, SWM_S_BORDER_WIDTH },
|
|
|
|
{ "autorun", setautorun, 0 },
|
2011-06-23 17:52:39 +00:00
|
|
|
{ "layout", setlayout, 0 },
|
2009-08-11 16:20:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2011-10-25 22:40:12 -04:00
|
|
|
conf_load(char *filename, int keymapping)
|
2009-08-11 16:20:55 +00:00
|
|
|
{
|
|
|
|
FILE *config;
|
|
|
|
char *line, *cp, *optsub, *optval;
|
|
|
|
size_t linelen, lineno = 0;
|
|
|
|
int wordlen, i, optind;
|
|
|
|
struct config_option *opt;
|
2009-09-25 19:25:29 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_CONF, "conf_load: begin\n");
|
2009-09-25 19:25:29 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
if (filename == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("conf_load: no filename");
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if ((config = fopen(filename, "r")) == NULL) {
|
2011-10-25 22:40:12 -04:00
|
|
|
warn("conf_load: fopen: %s", filename);
|
2009-09-12 21:32:21 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2009-09-25 19:25:29 +00:00
|
|
|
|
2009-08-11 16:20:55 +00:00
|
|
|
while (!feof(config)) {
|
|
|
|
if ((line = fparseln(config, &linelen, &lineno, NULL, 0))
|
|
|
|
== NULL) {
|
|
|
|
if (ferror(config))
|
|
|
|
err(1, "%s", filename);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp = line;
|
|
|
|
cp += strspn(cp, " \t\n"); /* eat whitespace */
|
|
|
|
if (cp[0] == '\0') {
|
|
|
|
/* empty line */
|
|
|
|
free(line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* get config option */
|
|
|
|
wordlen = strcspn(cp, "=[ \t\n");
|
2009-09-12 21:32:21 +00:00
|
|
|
if (wordlen == 0) {
|
2009-08-11 16:20:55 +00:00
|
|
|
warnx("%s: line %zd: no option found",
|
|
|
|
filename, lineno);
|
2012-01-19 21:43:04 -05:00
|
|
|
goto out;
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
optind = -1;
|
|
|
|
for (i = 0; i < LENGTH(configopt); i++) {
|
|
|
|
opt = &configopt[i];
|
|
|
|
if (!strncasecmp(cp, opt->optname, wordlen) &&
|
|
|
|
strlen(opt->optname) == wordlen) {
|
|
|
|
optind = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind == -1) {
|
|
|
|
warnx("%s: line %zd: unknown option %.*s",
|
|
|
|
filename, lineno, wordlen, cp);
|
2012-01-19 21:43:04 -05:00
|
|
|
goto out;
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
2011-10-25 22:40:12 -04:00
|
|
|
if (keymapping && strcmp(opt->optname, "bind")) {
|
|
|
|
warnx("%s: line %zd: invalid option %.*s",
|
|
|
|
filename, lineno, wordlen, cp);
|
2012-01-19 21:43:04 -05:00
|
|
|
goto out;
|
2011-10-25 22:40:12 -04:00
|
|
|
}
|
2009-08-11 16:20:55 +00:00
|
|
|
cp += wordlen;
|
|
|
|
cp += strspn(cp, " \t\n"); /* eat whitespace */
|
|
|
|
/* get [selector] if any */
|
|
|
|
optsub = NULL;
|
|
|
|
if (*cp == '[') {
|
|
|
|
cp++;
|
|
|
|
wordlen = strcspn(cp, "]");
|
2009-09-12 21:32:21 +00:00
|
|
|
if (*cp != ']') {
|
|
|
|
if (wordlen == 0) {
|
|
|
|
warnx("%s: line %zd: syntax error",
|
|
|
|
filename, lineno);
|
2012-01-19 21:43:04 -05:00
|
|
|
goto out;
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
2012-01-22 03:38:04 +08:00
|
|
|
|
2012-01-23 19:17:16 +00:00
|
|
|
if (asprintf(&optsub, "%.*s", wordlen, cp) ==
|
2012-01-22 03:38:04 +08:00
|
|
|
-1) {
|
|
|
|
warnx("%s: line %zd: unable to allocate"
|
|
|
|
"memory for selector", filename,
|
|
|
|
lineno);
|
2012-01-23 19:17:16 +00:00
|
|
|
goto out;
|
2012-01-22 03:38:04 +08:00
|
|
|
}
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
cp += wordlen;
|
|
|
|
cp += strspn(cp, "] \t\n"); /* eat trailing */
|
|
|
|
}
|
|
|
|
cp += strspn(cp, "= \t\n"); /* eat trailing */
|
|
|
|
/* get RHS value */
|
|
|
|
optval = strdup(cp);
|
|
|
|
/* call function to deal with it all */
|
2009-09-12 21:32:21 +00:00
|
|
|
if (configopt[optind].func(optsub, optval,
|
2012-02-02 23:55:19 +00:00
|
|
|
configopt[optind].funcflags) != 0)
|
2009-08-11 16:20:55 +00:00
|
|
|
errx(1, "%s: line %zd: invalid data for %s",
|
|
|
|
filename, lineno, configopt[optind].optname);
|
|
|
|
free(optval);
|
|
|
|
free(optsub);
|
|
|
|
free(line);
|
|
|
|
}
|
2009-09-25 19:25:29 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
fclose(config);
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_CONF, "conf_load: end\n");
|
2009-09-25 19:25:29 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
return (0);
|
2012-01-19 21:43:04 -05:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(line);
|
|
|
|
fclose(config);
|
2012-02-02 07:00:45 +08:00
|
|
|
DNPRINTF(SWM_D_CONF, "conf_load: end with error.\n");
|
2012-01-19 21:43:04 -05:00
|
|
|
|
|
|
|
return (1);
|
2009-08-11 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 22:18:45 +00:00
|
|
|
void
|
2011-06-10 20:11:11 +00:00
|
|
|
set_child_transient(struct ws_win *win, Window *trans)
|
2009-10-15 22:18:45 +00:00
|
|
|
{
|
2011-06-10 20:11:11 +00:00
|
|
|
struct ws_win *parent, *w;
|
|
|
|
XWMHints *wmh = NULL;
|
|
|
|
struct swm_region *r;
|
|
|
|
struct workspace *ws;
|
2009-10-15 22:18:45 +00:00
|
|
|
|
|
|
|
parent = find_window(win->transient);
|
|
|
|
if (parent)
|
|
|
|
parent->child_trans = win;
|
2011-06-10 20:11:11 +00:00
|
|
|
else {
|
|
|
|
DNPRINTF(SWM_D_MISC, "set_child_transient: parent doesn't exist"
|
2012-01-29 01:29:31 +08:00
|
|
|
" for 0x%lx trans 0x%lx\n", win->id, win->transient);
|
2011-06-10 20:11:11 +00:00
|
|
|
|
|
|
|
if (win->hints == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("no hints for 0x%lx", win->id);
|
2011-06-10 20:11:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = root_to_region(win->wa.root);
|
|
|
|
ws = r->ws;
|
|
|
|
/* parent doen't exist in our window list */
|
|
|
|
TAILQ_FOREACH(w, &ws->winlist, entry) {
|
|
|
|
if (wmh)
|
|
|
|
XFree(wmh);
|
|
|
|
|
|
|
|
if ((wmh = XGetWMHints(display, w->id)) == NULL) {
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("can't get hints for 0x%lx", w->id);
|
2011-06-10 20:11:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (win->hints->window_group != wmh->window_group)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
w->child_trans = win;
|
|
|
|
win->transient = w->id;
|
|
|
|
*trans = w->id;
|
|
|
|
DNPRINTF(SWM_D_MISC, "set_child_transient: asjusting "
|
2012-01-29 01:29:31 +08:00
|
|
|
"transient to 0x%lx\n", win->transient);
|
2011-06-10 20:11:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wmh)
|
|
|
|
XFree(wmh);
|
2009-10-15 22:18:45 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
long
|
|
|
|
window_get_pid(Window win)
|
|
|
|
{
|
|
|
|
Atom actual_type_return;
|
|
|
|
int actual_format_return = 0;
|
|
|
|
unsigned long nitems_return = 0;
|
|
|
|
unsigned long bytes_after_return = 0;
|
2011-06-23 11:37:16 +00:00
|
|
|
long *pid = NULL;
|
2011-06-23 02:15:53 +00:00
|
|
|
long ret = 0;
|
2011-06-23 12:13:19 +00:00
|
|
|
const char *errstr;
|
|
|
|
unsigned char *prop = NULL;
|
2011-06-23 02:15:53 +00:00
|
|
|
|
|
|
|
if (XGetWindowProperty(display, win,
|
|
|
|
XInternAtom(display, "_NET_WM_PID", False), 0, 1, False,
|
|
|
|
XA_CARDINAL, &actual_type_return, &actual_format_return,
|
|
|
|
&nitems_return, &bytes_after_return,
|
|
|
|
(unsigned char**)(void*)&pid) != Success)
|
2011-06-23 12:13:19 +00:00
|
|
|
goto tryharder;
|
2011-06-23 11:37:16 +00:00
|
|
|
if (actual_type_return != XA_CARDINAL)
|
2011-06-23 12:13:19 +00:00
|
|
|
goto tryharder;
|
2011-06-23 11:37:16 +00:00
|
|
|
if (pid == NULL)
|
2011-06-23 12:13:19 +00:00
|
|
|
goto tryharder;
|
2011-06-23 02:15:53 +00:00
|
|
|
|
2011-06-23 11:37:16 +00:00
|
|
|
ret = *pid;
|
2011-06-23 02:15:53 +00:00
|
|
|
XFree(pid);
|
|
|
|
|
2011-06-23 12:13:19 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
tryharder:
|
|
|
|
if (XGetWindowProperty(display, win,
|
|
|
|
XInternAtom(display, "_SWM_PID", False), 0, SWM_PROPLEN, False,
|
|
|
|
XA_STRING, &actual_type_return, &actual_format_return,
|
|
|
|
&nitems_return, &bytes_after_return, &prop) != Success)
|
|
|
|
return (0);
|
|
|
|
if (actual_type_return != XA_STRING)
|
|
|
|
return (0);
|
|
|
|
if (prop == NULL)
|
|
|
|
return (0);
|
|
|
|
|
2011-09-19 21:56:45 -05:00
|
|
|
ret = strtonum((const char *)prop, 0, UINT_MAX, &errstr);
|
2011-06-23 12:13:19 +00:00
|
|
|
/* ignore error because strtonum returns 0 anyway */
|
|
|
|
XFree(prop);
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2009-01-15 02:14:08 +00:00
|
|
|
struct ws_win *
|
2009-01-23 01:01:48 +00:00
|
|
|
manage_window(Window id)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2009-10-01 21:08:22 +00:00
|
|
|
Window trans = 0;
|
2009-01-23 01:01:48 +00:00
|
|
|
struct workspace *ws;
|
2009-10-15 22:18:45 +00:00
|
|
|
struct ws_win *win, *ww;
|
2009-09-30 21:23:55 +00:00
|
|
|
int format, i, ws_idx, n, border_me = 0;
|
2009-01-23 01:01:48 +00:00
|
|
|
unsigned long nitems, bytes;
|
|
|
|
Atom ws_idx_atom = 0, type;
|
2009-02-10 18:16:10 +00:00
|
|
|
Atom *prot = NULL, *pp;
|
2009-01-24 17:57:26 +00:00
|
|
|
unsigned char ws_idx_str[SWM_PROPLEN], *prop = NULL;
|
2009-01-23 01:01:48 +00:00
|
|
|
struct swm_region *r;
|
2012-02-17 10:57:29 -06:00
|
|
|
long mask = 0;
|
2009-01-28 04:45:45 +00:00
|
|
|
const char *errstr;
|
2009-02-03 21:50:16 +00:00
|
|
|
XWindowChanges wc;
|
2011-06-23 02:15:53 +00:00
|
|
|
struct pid_e *p;
|
2012-02-02 21:44:21 +00:00
|
|
|
struct quirk *qp;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-01-23 01:01:48 +00:00
|
|
|
if ((win = find_window(id)) != NULL)
|
2009-10-13 02:28:47 +00:00
|
|
|
return (win); /* already being managed */
|
|
|
|
|
|
|
|
/* see if we are on the unmanaged list */
|
|
|
|
if ((win = find_unmanaged_window(id)) != NULL) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "manage_window: previously unmanaged "
|
|
|
|
"window: 0x%lx\n", win->id);
|
2009-10-13 02:28:47 +00:00
|
|
|
TAILQ_REMOVE(&win->ws->unmanagedlist, win, entry);
|
2012-05-23 18:31:11 +08:00
|
|
|
if (win->transient)
|
2011-06-10 20:11:11 +00:00
|
|
|
set_child_transient(win, &trans);
|
2012-05-23 18:31:11 +08:00
|
|
|
|
|
|
|
if (trans && (ww = find_window(trans)))
|
2011-06-07 20:56:29 +00:00
|
|
|
TAILQ_INSERT_AFTER(&win->ws->winlist, ww, win, entry);
|
2012-05-23 18:31:11 +08:00
|
|
|
else if ((ww = win->ws->focus) &&
|
|
|
|
spawn_position == SWM_STACK_ABOVE)
|
|
|
|
TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
|
|
|
|
else if (ww && spawn_position == SWM_STACK_BELOW)
|
|
|
|
TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
|
|
|
|
else switch (spawn_position) {
|
|
|
|
default:
|
|
|
|
case SWM_STACK_TOP:
|
|
|
|
case SWM_STACK_ABOVE:
|
2011-06-07 20:56:29 +00:00
|
|
|
TAILQ_INSERT_TAIL(&win->ws->winlist, win, entry);
|
2012-05-23 18:31:11 +08:00
|
|
|
break;
|
|
|
|
case SWM_STACK_BOTTOM:
|
|
|
|
case SWM_STACK_BELOW:
|
|
|
|
TAILQ_INSERT_HEAD(&win->ws->winlist, win, entry);
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_actions(win);
|
2009-10-13 02:28:47 +00:00
|
|
|
return (win);
|
|
|
|
}
|
2009-01-14 19:08:56 +00:00
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
if ((win = calloc(1, sizeof(struct ws_win))) == NULL)
|
2012-01-29 01:29:31 +08:00
|
|
|
err(1, "manage_window: calloc: failed to allocate memory for "
|
|
|
|
"new window");
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
win->id = id;
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
/* see if we need to override the workspace */
|
|
|
|
p = find_pid(window_get_pid(id));
|
|
|
|
|
2009-02-01 01:45:43 +00:00
|
|
|
/* Get all the window data in one shot */
|
2009-01-23 01:01:48 +00:00
|
|
|
ws_idx_atom = XInternAtom(display, "_SWM_WS", False);
|
2011-06-23 02:15:53 +00:00
|
|
|
if (ws_idx_atom) {
|
2009-01-24 17:57:26 +00:00
|
|
|
XGetWindowProperty(display, id, ws_idx_atom, 0, SWM_PROPLEN,
|
|
|
|
False, XA_STRING, &type, &format, &nitems, &bytes, &prop);
|
2011-06-23 02:15:53 +00:00
|
|
|
}
|
2009-01-23 01:01:48 +00:00
|
|
|
XGetWindowAttributes(display, id, &win->wa);
|
2012-02-04 01:58:52 +08:00
|
|
|
XGetWMNormalHints(display, id, &win->sh, &win->sh_mask);
|
2011-06-10 20:11:11 +00:00
|
|
|
win->hints = XGetWMHints(display, id);
|
2009-02-01 01:45:43 +00:00
|
|
|
XGetTransientForHint(display, id, &trans);
|
|
|
|
if (trans) {
|
|
|
|
win->transient = trans;
|
2011-06-10 20:11:11 +00:00
|
|
|
set_child_transient(win, &trans);
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "manage_window: window: 0x%lx, "
|
|
|
|
"transient: 0x%lx\n", win->id, win->transient);
|
2009-02-01 01:45:43 +00:00
|
|
|
}
|
2010-09-16 02:26:45 +00:00
|
|
|
|
2009-02-10 18:16:10 +00:00
|
|
|
/* get supported protocols */
|
|
|
|
if (XGetWMProtocols(display, id, &prot, &n)) {
|
2009-10-07 02:38:38 +00:00
|
|
|
for (i = 0, pp = prot; i < n; i++, pp++) {
|
|
|
|
if (*pp == takefocus)
|
|
|
|
win->take_focus = 1;
|
2009-02-10 18:16:10 +00:00
|
|
|
if (*pp == adelete)
|
|
|
|
win->can_delete = 1;
|
2009-10-07 02:38:38 +00:00
|
|
|
}
|
2009-02-10 18:16:10 +00:00
|
|
|
if (prot)
|
|
|
|
XFree(prot);
|
|
|
|
}
|
2009-02-03 05:08:27 +00:00
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
win->iconic = get_iconic(win);
|
|
|
|
|
2009-02-01 01:45:43 +00:00
|
|
|
/*
|
|
|
|
* Figure out where to put the window. If it was previously assigned to
|
|
|
|
* a workspace (either by spawn() or manually moving), and isn't
|
|
|
|
* transient, * put it in the same workspace
|
|
|
|
*/
|
2009-01-23 01:01:48 +00:00
|
|
|
r = root_to_region(win->wa.root);
|
2011-06-23 02:15:53 +00:00
|
|
|
if (p) {
|
|
|
|
ws = &r->s->ws[p->ws];
|
|
|
|
TAILQ_REMOVE(&pidlist, p, entry);
|
|
|
|
free(p);
|
|
|
|
p = NULL;
|
|
|
|
} else if (prop && win->transient == 0) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_PROP, "manage_window: get _SWM_WS: %s\n", prop);
|
2012-04-08 01:59:41 +08:00
|
|
|
ws_idx = strtonum((const char *)prop, 0, workspace_limit - 1,
|
|
|
|
&errstr);
|
2009-02-01 03:04:45 +00:00
|
|
|
if (errstr) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "manage_window: window: #%s: %s",
|
2009-01-24 17:57:26 +00:00
|
|
|
errstr, prop);
|
2009-02-01 03:04:45 +00:00
|
|
|
}
|
2009-01-24 17:57:26 +00:00
|
|
|
ws = &r->s->ws[ws_idx];
|
2009-09-29 22:35:02 +00:00
|
|
|
} else {
|
2009-01-23 01:01:48 +00:00
|
|
|
ws = r->ws;
|
2009-09-29 22:35:02 +00:00
|
|
|
/* this should launch transients in the same ws as parent */
|
2009-09-30 20:15:02 +00:00
|
|
|
if (id && trans)
|
|
|
|
if ((ww = find_window(trans)) != NULL)
|
|
|
|
if (ws->r) {
|
|
|
|
ws = ww->ws;
|
2009-10-01 21:08:22 +00:00
|
|
|
if (ww->ws->r)
|
|
|
|
r = ww->ws->r;
|
|
|
|
else
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("manage_window: fix this "
|
|
|
|
"bug mcbride");
|
2009-09-30 21:23:55 +00:00
|
|
|
border_me = 1;
|
2009-09-30 20:15:02 +00:00
|
|
|
}
|
2009-09-29 22:35:02 +00:00
|
|
|
}
|
2009-01-23 01:01:48 +00:00
|
|
|
|
2009-02-01 01:45:43 +00:00
|
|
|
/* set up the window layout */
|
2009-01-15 02:14:08 +00:00
|
|
|
win->id = id;
|
2009-01-19 05:48:11 +00:00
|
|
|
win->ws = ws;
|
2009-01-23 01:01:48 +00:00
|
|
|
win->s = r->s; /* this never changes */
|
2011-06-07 20:56:29 +00:00
|
|
|
if (trans && (ww = find_window(trans)))
|
|
|
|
TAILQ_INSERT_AFTER(&ws->winlist, ww, win, entry);
|
2012-05-23 18:31:11 +08:00
|
|
|
else if (spawn_position == SWM_STACK_ABOVE && win->ws->focus)
|
|
|
|
TAILQ_INSERT_AFTER(&win->ws->winlist, win->ws->focus, win, entry);
|
2011-06-07 20:56:29 +00:00
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&ws->winlist, win, entry);
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = win->wa.width;
|
|
|
|
HEIGHT(win) = win->wa.height;
|
|
|
|
X(win) = win->wa.x;
|
|
|
|
Y(win) = win->wa.y;
|
2010-07-01 20:58:00 +00:00
|
|
|
win->g_floatvalid = 0;
|
|
|
|
win->floatmaxed = 0;
|
2010-09-16 02:26:45 +00:00
|
|
|
win->ewmh_flags = 0;
|
2009-01-23 01:01:48 +00:00
|
|
|
|
2009-02-01 01:45:43 +00:00
|
|
|
/* Set window properties so we can remember this after reincarnation */
|
2009-01-24 17:57:26 +00:00
|
|
|
if (ws_idx_atom && prop == NULL &&
|
2011-09-19 21:56:45 -05:00
|
|
|
snprintf((char *)ws_idx_str, SWM_PROPLEN, "%d", ws->idx) <
|
|
|
|
SWM_PROPLEN) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_PROP, "manage_window: set _SWM_WS: %s\n",
|
2009-01-24 17:57:26 +00:00
|
|
|
ws_idx_str);
|
|
|
|
XChangeProperty(display, win->id, ws_idx_atom, XA_STRING, 8,
|
2012-02-13 23:32:31 +08:00
|
|
|
PropModeReplace, ws_idx_str, strlen((char *)ws_idx_str));
|
2009-01-23 01:01:48 +00:00
|
|
|
}
|
2010-09-16 02:26:45 +00:00
|
|
|
if (prop)
|
|
|
|
XFree(prop);
|
|
|
|
|
|
|
|
ewmh_autoquirk(win);
|
2009-01-23 01:01:48 +00:00
|
|
|
|
2009-01-29 20:35:01 +00:00
|
|
|
if (XGetClassHint(display, win->id, &win->ch)) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_CLASS, "manage_window: class: %s, name: %s\n",
|
2009-01-29 20:35:01 +00:00
|
|
|
win->ch.res_class, win->ch.res_name);
|
2009-10-06 17:04:53 +00:00
|
|
|
|
|
|
|
/* java is retarded so treat it special */
|
2009-10-15 20:42:59 +00:00
|
|
|
if (strstr(win->ch.res_name, "sun-awt")) {
|
2009-10-06 17:04:53 +00:00
|
|
|
win->java = 1;
|
2009-10-15 20:42:59 +00:00
|
|
|
border_me = 1;
|
|
|
|
}
|
2009-10-06 17:04:53 +00:00
|
|
|
|
2012-02-02 21:44:21 +00:00
|
|
|
TAILQ_FOREACH(qp, &quirks, entry) {
|
|
|
|
if (!strcmp(win->ch.res_class, qp->class) &&
|
|
|
|
!strcmp(win->ch.res_name, qp->name)) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_CLASS, "manage_window: found: "
|
|
|
|
"class: %s, name: %s\n", win->ch.res_class,
|
|
|
|
win->ch.res_name);
|
2012-02-02 21:44:21 +00:00
|
|
|
if (qp->quirk & SWM_Q_FLOAT) {
|
2009-01-29 20:27:11 +00:00
|
|
|
win->floating = 1;
|
2009-10-13 14:32:18 +00:00
|
|
|
border_me = 1;
|
|
|
|
}
|
2012-02-02 21:44:21 +00:00
|
|
|
win->quirks = qp->quirk;
|
2009-01-29 20:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-16 23:40:01 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 21:50:16 +00:00
|
|
|
/* alter window position if quirky */
|
|
|
|
if (win->quirks & SWM_Q_ANYWHERE) {
|
|
|
|
win->manual = 1; /* don't center the quirky windows */
|
|
|
|
bzero(&wc, sizeof wc);
|
|
|
|
mask = 0;
|
2012-01-29 01:29:31 +08:00
|
|
|
if (bar_enabled && Y(win) < bar_height) {
|
|
|
|
Y(win) = wc.y = bar_height;
|
2009-02-03 21:50:16 +00:00
|
|
|
mask |= CWY;
|
|
|
|
}
|
2012-01-29 01:29:31 +08:00
|
|
|
if (WIDTH(win) + X(win) > WIDTH(r)) {
|
|
|
|
X(win) = wc.x = WIDTH(r) - WIDTH(win) - 2;
|
2009-02-03 21:50:16 +00:00
|
|
|
mask |= CWX;
|
|
|
|
}
|
2009-09-30 21:23:55 +00:00
|
|
|
border_me = 1;
|
2009-02-03 21:50:16 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 07:24:02 +00:00
|
|
|
/* Reset font sizes (the bruteforce way; no default keybinding). */
|
|
|
|
if (win->quirks & SWM_Q_XTERM_FONTADJ) {
|
|
|
|
for (i = 0; i < SWM_MAX_FONT_STEPS; i++)
|
|
|
|
fake_keypress(win, XK_KP_Subtract, ShiftMask);
|
|
|
|
for (i = 0; i < SWM_MAX_FONT_STEPS; i++)
|
|
|
|
fake_keypress(win, XK_KP_Add, ShiftMask);
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_get_win_state(win);
|
|
|
|
ewmh_update_actions(win);
|
|
|
|
ewmh_update_win_state(win, None, _NET_WM_STATE_REMOVE);
|
|
|
|
|
2009-09-30 21:23:55 +00:00
|
|
|
/* border me */
|
|
|
|
if (border_me) {
|
|
|
|
bzero(&wc, sizeof wc);
|
2011-03-11 14:12:49 +00:00
|
|
|
wc.border_width = border_width;
|
2012-02-17 10:57:29 -06:00
|
|
|
mask |= CWBorderWidth;
|
2009-09-30 21:23:55 +00:00
|
|
|
XConfigureWindow(display, win->id, mask, &wc);
|
|
|
|
}
|
|
|
|
|
2009-01-18 01:19:01 +00:00
|
|
|
XSelectInput(display, id, EnterWindowMask | FocusChangeMask |
|
|
|
|
PropertyChangeMask | StructureNotifyMask);
|
2009-01-17 19:57:48 +00:00
|
|
|
|
2009-02-03 22:04:50 +00:00
|
|
|
/* floaters need to be mapped if they are in the current workspace */
|
2009-09-30 21:23:55 +00:00
|
|
|
if ((win->floating || win->transient) && (ws->idx == r->ws->idx))
|
2009-02-03 21:50:16 +00:00
|
|
|
XMapRaised(display, win->id);
|
|
|
|
|
2009-01-16 19:13:36 +00:00
|
|
|
return (win);
|
2009-01-15 02:14:08 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 02:28:47 +00:00
|
|
|
void
|
|
|
|
free_window(struct ws_win *win)
|
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "free_window: window: 0x%lx\n", win->id);
|
2009-10-13 02:28:47 +00:00
|
|
|
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* needed for restart wm */
|
|
|
|
set_win_state(win, WithdrawnState);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&win->ws->unmanagedlist, win, entry);
|
|
|
|
|
|
|
|
if (win->ch.res_class)
|
|
|
|
XFree(win->ch.res_class);
|
|
|
|
if (win->ch.res_name)
|
|
|
|
XFree(win->ch.res_name);
|
2009-10-15 20:42:59 +00:00
|
|
|
|
|
|
|
kill_refs(win);
|
|
|
|
|
|
|
|
/* paint memory */
|
|
|
|
memset(win, 0xff, sizeof *win); /* XXX kill later */
|
|
|
|
|
2009-10-13 02:28:47 +00:00
|
|
|
free(win);
|
|
|
|
}
|
|
|
|
|
2009-02-03 00:50:01 +00:00
|
|
|
void
|
|
|
|
unmanage_window(struct ws_win *win)
|
|
|
|
{
|
2009-10-07 02:38:38 +00:00
|
|
|
struct ws_win *parent;
|
2009-02-03 00:54:35 +00:00
|
|
|
|
2009-02-03 00:50:01 +00:00
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_MISC, "unmanage_window: window: 0x%lx\n", win->id);
|
2009-02-03 00:50:01 +00:00
|
|
|
|
2009-10-07 02:38:38 +00:00
|
|
|
if (win->transient) {
|
|
|
|
parent = find_window(win->transient);
|
|
|
|
if (parent)
|
|
|
|
parent->child_trans = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-19 17:37:56 +00:00
|
|
|
/* focus on root just in case */
|
|
|
|
XSetInputFocus(display, PointerRoot, PointerRoot, CurrentTime);
|
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_prev(win);
|
2009-11-06 04:41:28 +00:00
|
|
|
|
2012-02-03 08:01:09 -06:00
|
|
|
if (win->hints) {
|
|
|
|
XFree(win->hints);
|
|
|
|
win->hints = NULL;
|
|
|
|
}
|
2012-02-02 07:00:45 +08:00
|
|
|
|
2009-02-03 00:50:01 +00:00
|
|
|
TAILQ_REMOVE(&win->ws->winlist, win, entry);
|
2009-10-13 02:28:47 +00:00
|
|
|
TAILQ_INSERT_TAIL(&win->ws->unmanagedlist, win, entry);
|
2009-02-03 00:50:01 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 02:38:38 +00:00
|
|
|
void
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(struct ws_win *win)
|
2009-10-07 02:38:38 +00:00
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "focus_magic: window: 0x%lx\n", WINID(win));
|
2009-10-20 22:42:35 +00:00
|
|
|
|
2012-02-08 01:07:46 +00:00
|
|
|
if (win == NULL) {
|
|
|
|
/* if there are no windows clear the status-bar */
|
2012-05-12 22:05:21 +01:00
|
|
|
bar_update();
|
2009-10-15 20:42:59 +00:00
|
|
|
return;
|
2012-02-08 01:07:46 +00:00
|
|
|
}
|
2009-10-15 20:42:59 +00:00
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
if (win->child_trans) {
|
2009-10-07 02:38:38 +00:00
|
|
|
/* win = parent & has a transient so focus on that */
|
|
|
|
if (win->java) {
|
|
|
|
focus_win(win->child_trans);
|
|
|
|
if (win->child_trans->take_focus)
|
|
|
|
client_msg(win, takefocus);
|
|
|
|
} else {
|
2012-02-08 01:17:18 +00:00
|
|
|
/* make sure transient hasn't disappeared */
|
2010-08-11 03:15:40 +00:00
|
|
|
if (validate_win(win->child_trans) == 0) {
|
|
|
|
focus_win(win->child_trans);
|
|
|
|
if (win->child_trans->take_focus)
|
|
|
|
client_msg(win->child_trans, takefocus);
|
|
|
|
} else {
|
|
|
|
win->child_trans = NULL;
|
|
|
|
focus_win(win);
|
|
|
|
if (win->take_focus)
|
|
|
|
client_msg(win, takefocus);
|
|
|
|
}
|
2009-10-07 02:38:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* regular focus */
|
|
|
|
focus_win(win);
|
|
|
|
if (win->take_focus)
|
|
|
|
client_msg(win, takefocus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 03:28:46 +00:00
|
|
|
void
|
|
|
|
expose(XEvent *e)
|
|
|
|
{
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "expose: window: 0x%lx\n", e->xexpose.window);
|
2009-10-02 03:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
keypress(XEvent *e)
|
|
|
|
{
|
2011-10-06 11:30:45 -05:00
|
|
|
KeySym keysym;
|
2009-10-02 03:28:46 +00:00
|
|
|
XKeyEvent *ev = &e->xkey;
|
2012-02-02 21:19:17 +00:00
|
|
|
struct key *kp;
|
2012-02-09 17:19:00 +00:00
|
|
|
struct swm_region *r;
|
2009-10-02 03:28:46 +00:00
|
|
|
|
2012-05-16 00:22:59 -04:00
|
|
|
keysym = XkbKeycodeToKeysym(display, (KeyCode)ev->keycode, 0, 0);
|
2012-02-09 17:19:00 +00:00
|
|
|
if ((kp = key_lookup(CLEANMASK(ev->state), keysym)) == NULL)
|
|
|
|
return;
|
|
|
|
if (keyfuncs[kp->funcid].func == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = root_to_region(ev->root);
|
|
|
|
if (kp->funcid == kf_spawn_custom)
|
|
|
|
spawn_custom(r, &(keyfuncs[kp->funcid].args), kp->spawn_name);
|
|
|
|
else
|
|
|
|
keyfuncs[kp->funcid].func(r, &(keyfuncs[kp->funcid].args));
|
2009-10-02 03:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
buttonpress(XEvent *e)
|
|
|
|
{
|
|
|
|
struct ws_win *win;
|
|
|
|
int i, action;
|
2009-10-15 20:42:59 +00:00
|
|
|
XButtonPressedEvent *ev = &e->xbutton;
|
2009-10-02 03:28:46 +00:00
|
|
|
|
|
|
|
if ((win = find_window(ev->window)) == NULL)
|
|
|
|
return;
|
2009-10-07 02:38:38 +00:00
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(win);
|
2009-10-07 02:38:38 +00:00
|
|
|
action = client_click;
|
2009-10-02 03:28:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < LENGTH(buttons); i++)
|
|
|
|
if (action == buttons[i].action && buttons[i].func &&
|
|
|
|
buttons[i].button == ev->button &&
|
|
|
|
CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
|
|
|
|
buttons[i].func(win, &buttons[i].args);
|
|
|
|
}
|
|
|
|
|
2009-01-15 02:14:08 +00:00
|
|
|
void
|
|
|
|
configurerequest(XEvent *e)
|
|
|
|
{
|
|
|
|
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
|
|
|
struct ws_win *win;
|
2009-01-22 22:57:30 +00:00
|
|
|
int new = 0;
|
2009-01-16 23:40:01 +00:00
|
|
|
XWindowChanges wc;
|
2009-01-15 02:14:08 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
if ((win = find_window(ev->window)) == NULL)
|
2009-10-13 14:32:18 +00:00
|
|
|
if ((win = find_unmanaged_window(ev->window)) == NULL)
|
|
|
|
new = 1;
|
2009-01-16 23:40:01 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "configurerequest: window: 0x%lx, new: %s\n",
|
|
|
|
ev->window, YESNO(new));
|
|
|
|
|
2009-01-16 23:40:01 +00:00
|
|
|
if (new) {
|
|
|
|
bzero(&wc, sizeof wc);
|
|
|
|
wc.x = ev->x;
|
|
|
|
wc.y = ev->y;
|
|
|
|
wc.width = ev->width;
|
|
|
|
wc.height = ev->height;
|
|
|
|
wc.border_width = ev->border_width;
|
|
|
|
wc.sibling = ev->above;
|
|
|
|
wc.stack_mode = ev->detail;
|
|
|
|
XConfigureWindow(display, ev->window, ev->value_mask, &wc);
|
2012-05-12 21:28:49 +01:00
|
|
|
} else
|
2011-06-03 20:55:02 +00:00
|
|
|
config_win(win, ev);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
configurenotify(XEvent *e)
|
|
|
|
{
|
2009-02-07 19:49:58 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "configurenotify: window: 0x%lx\n",
|
2009-01-14 05:14:13 +00:00
|
|
|
e->xconfigure.window);
|
2009-02-07 19:49:58 +00:00
|
|
|
|
|
|
|
win = find_window(e->xconfigure.window);
|
2009-02-16 04:45:35 +00:00
|
|
|
if (win) {
|
2012-02-04 01:58:52 +08:00
|
|
|
XGetWMNormalHints(display, win->id, &win->sh, &win->sh_mask);
|
2009-02-16 04:45:35 +00:00
|
|
|
adjust_font(win);
|
|
|
|
if (font_adjusted)
|
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-02-16 04:45:35 +00:00
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
destroynotify(XEvent *e)
|
|
|
|
{
|
2009-10-15 20:42:59 +00:00
|
|
|
struct ws_win *win;
|
2009-01-13 15:55:13 +00:00
|
|
|
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "destroynotify: window: 0x%lx\n", ev->window);
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-10-13 02:28:47 +00:00
|
|
|
if ((win = find_window(ev->window)) == NULL) {
|
|
|
|
if ((win = find_unmanaged_window(ev->window)) == NULL)
|
|
|
|
return;
|
2009-10-14 13:56:02 +00:00
|
|
|
free_window(win);
|
|
|
|
return;
|
2009-10-13 02:28:47 +00:00
|
|
|
}
|
2009-10-05 17:03:47 +00:00
|
|
|
|
2009-11-06 04:41:28 +00:00
|
|
|
/* make sure we focus on something */
|
|
|
|
win->floating = 0;
|
|
|
|
|
2009-10-14 13:56:02 +00:00
|
|
|
unmanage_window(win);
|
2009-10-13 02:28:47 +00:00
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-10-18 15:06:15 +00:00
|
|
|
free_window(win);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
enternotify(XEvent *e)
|
|
|
|
{
|
|
|
|
XCrossingEvent *ev = &e->xcrossing;
|
2009-10-23 16:39:45 +00:00
|
|
|
XEvent cne;
|
2009-11-06 04:55:18 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
#if 0
|
|
|
|
struct ws_win *w;
|
2009-10-29 18:47:48 +00:00
|
|
|
Window focus_return;
|
|
|
|
int revert_to_return;
|
2009-11-06 04:55:18 +00:00
|
|
|
#endif
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "enternotify: window: 0x%lx, mode: %d, detail: "
|
|
|
|
"%d, root: 0x%lx, subwindow: 0x%lx, same_screen: %s, focus: %s, "
|
|
|
|
"state: %d\n", ev->window, ev->mode, ev->detail, ev->root,
|
|
|
|
ev->subwindow, YESNO(ev->same_screen), YESNO(ev->focus), ev->state);
|
2009-10-23 16:39:45 +00:00
|
|
|
|
2012-01-22 03:46:46 +08:00
|
|
|
if (ev->mode != NotifyNormal) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "skip enternotify: generated by "
|
|
|
|
"cursor grab.\n");
|
2012-01-22 03:46:46 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-30 00:09:19 +00:00
|
|
|
switch (focus_mode) {
|
|
|
|
case SWM_FOCUS_DEFAULT:
|
|
|
|
break;
|
|
|
|
case SWM_FOCUS_FOLLOW:
|
|
|
|
break;
|
|
|
|
case SWM_FOCUS_SYNERGY:
|
2009-11-06 04:41:28 +00:00
|
|
|
#if 0
|
2009-10-23 16:39:45 +00:00
|
|
|
/*
|
|
|
|
* all these checks need to be in this order because the
|
|
|
|
* XCheckTypedWindowEvent relies on weeding out the previous events
|
|
|
|
*
|
|
|
|
* making this code an option would enable a follow mouse for focus
|
|
|
|
* feature
|
|
|
|
*/
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-10-28 00:57:36 +00:00
|
|
|
/*
|
|
|
|
* state is set when we are switching workspaces and focus is set when
|
2009-10-29 11:16:33 +00:00
|
|
|
* the window or a subwindow already has focus (occurs during restart).
|
|
|
|
*
|
|
|
|
* Only honor the focus flag if last_focus_event is not FocusOut,
|
2012-02-15 14:09:13 -06:00
|
|
|
* this allows spectrwm to continue to control focus when another
|
2009-10-29 11:16:33 +00:00
|
|
|
* program is also playing with it.
|
2009-10-28 00:57:36 +00:00
|
|
|
*/
|
2009-10-29 11:16:33 +00:00
|
|
|
if (ev->state || (ev->focus && last_focus_event != FocusOut)) {
|
2009-10-27 10:42:46 +00:00
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring enternotify: focus\n");
|
2009-10-24 14:21:18 +00:00
|
|
|
return;
|
2009-10-27 10:42:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 21:23:59 +00:00
|
|
|
/*
|
|
|
|
* happens when a window is created or destroyed and the border
|
2009-10-23 16:39:45 +00:00
|
|
|
* crosses the mouse pointer and when switching ws
|
2009-10-24 14:21:18 +00:00
|
|
|
*
|
|
|
|
* we need the subwindow test to see if we came from root in order
|
|
|
|
* to give focus to floaters
|
2009-09-29 21:23:59 +00:00
|
|
|
*/
|
2009-10-24 14:21:18 +00:00
|
|
|
if (ev->mode == NotifyNormal && ev->detail == NotifyVirtual &&
|
2009-10-27 10:42:46 +00:00
|
|
|
ev->subwindow == 0) {
|
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring enternotify: NotifyVirtual\n");
|
2009-10-23 16:39:45 +00:00
|
|
|
return;
|
2009-10-27 10:42:46 +00:00
|
|
|
}
|
2009-10-23 16:39:45 +00:00
|
|
|
|
|
|
|
/* this window already has focus */
|
2009-10-27 10:42:46 +00:00
|
|
|
if (ev->mode == NotifyNormal && ev->detail == NotifyInferior) {
|
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring enternotify: win has focus\n");
|
2009-10-23 16:39:45 +00:00
|
|
|
return;
|
2009-10-27 10:42:46 +00:00
|
|
|
}
|
2009-10-23 16:39:45 +00:00
|
|
|
|
|
|
|
/* this window is being deleted or moved to another ws */
|
|
|
|
if (XCheckTypedWindowEvent(display, ev->window, ConfigureNotify,
|
|
|
|
&cne) == True) {
|
2009-10-27 10:42:46 +00:00
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring enternotify: configurenotify\n");
|
2009-10-23 16:39:45 +00:00
|
|
|
XPutBackEvent(display, &cne);
|
2009-09-29 21:23:59 +00:00
|
|
|
return;
|
2009-10-23 16:39:45 +00:00
|
|
|
}
|
2009-01-22 00:08:19 +00:00
|
|
|
|
2009-10-27 10:42:46 +00:00
|
|
|
if ((win = find_window(ev->window)) == NULL) {
|
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring enternotify: win == NULL\n");
|
2009-10-07 02:38:38 +00:00
|
|
|
return;
|
2009-10-27 10:42:46 +00:00
|
|
|
}
|
2009-10-07 02:38:38 +00:00
|
|
|
|
2009-10-29 11:16:33 +00:00
|
|
|
/*
|
|
|
|
* In fullstack kill all enters unless they come from a different ws
|
|
|
|
* (i.e. another region) or focus has been grabbed externally.
|
|
|
|
*/
|
|
|
|
if (win->ws->cur_layout->flags & SWM_L_FOCUSPREV &&
|
|
|
|
last_focus_event != FocusOut) {
|
|
|
|
XGetInputFocus(display, &focus_return, &revert_to_return);
|
|
|
|
if ((w = find_window(focus_return)) == NULL ||
|
|
|
|
w->ws == win->ws) {
|
|
|
|
DNPRINTF(SWM_D_EVENT, "ignoring event: fullstack\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-10-27 10:42:46 +00:00
|
|
|
}
|
2009-11-06 04:41:28 +00:00
|
|
|
#endif
|
2010-06-30 00:09:19 +00:00
|
|
|
break;
|
2009-11-06 04:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((win = find_window(ev->window)) == NULL) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "skip enternotify: window is NULL\n");
|
2009-11-06 04:41:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we have more enternotifies let them handle it in due time
|
|
|
|
*/
|
|
|
|
if (XCheckTypedEvent(display, EnterNotify, &cne) == True) {
|
2009-11-06 04:51:21 +00:00
|
|
|
DNPRINTF(SWM_D_EVENT,
|
2009-11-06 04:41:28 +00:00
|
|
|
"ignoring enternotify: got more enternotify\n");
|
|
|
|
XPutBackEvent(display, &cne);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-23 20:56:37 +00:00
|
|
|
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(win);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 11:16:33 +00:00
|
|
|
/* lets us use one switch statement for arbitrary mode/detail combinations */
|
|
|
|
#define MERGE_MEMBERS(a,b) (((a & 0xffff) << 16) | (b & 0xffff))
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-03-04 06:13:35 +00:00
|
|
|
void
|
2009-10-29 11:16:33 +00:00
|
|
|
focusevent(XEvent *e)
|
2009-03-04 06:13:35 +00:00
|
|
|
{
|
2009-11-06 04:41:28 +00:00
|
|
|
#if 0
|
2009-10-29 11:16:33 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
u_int32_t mode_detail;
|
|
|
|
XFocusChangeEvent *ev = &e->xfocus;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "focusevent: %s window: 0x%lx mode: %d "
|
|
|
|
"detail: %d\n", ev->type == FocusIn ? "entering" : "leaving",
|
2009-10-29 11:16:33 +00:00
|
|
|
ev->window, ev->mode, ev->detail);
|
|
|
|
|
2009-10-30 01:56:00 +00:00
|
|
|
if (last_focus_event == ev->type) {
|
|
|
|
DNPRINTF(SWM_D_FOCUS, "ignoring focusevent: bad ordering\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-29 11:16:33 +00:00
|
|
|
last_focus_event = ev->type;
|
|
|
|
mode_detail = MERGE_MEMBERS(ev->mode, ev->detail);
|
|
|
|
|
|
|
|
switch (mode_detail) {
|
|
|
|
/* synergy client focus operations */
|
|
|
|
case MERGE_MEMBERS(NotifyNormal, NotifyNonlinear):
|
|
|
|
case MERGE_MEMBERS(NotifyNormal, NotifyNonlinearVirtual):
|
|
|
|
|
|
|
|
/* synergy server focus operations */
|
|
|
|
case MERGE_MEMBERS(NotifyWhileGrabbed, NotifyNonlinear):
|
|
|
|
|
|
|
|
/* Entering applications like rdesktop that mangle the pointer */
|
|
|
|
case MERGE_MEMBERS(NotifyNormal, NotifyPointer):
|
|
|
|
|
|
|
|
if ((win = find_window(e->xfocus.window)) != NULL && win->ws->r)
|
|
|
|
XSetWindowBorder(display, win->id,
|
|
|
|
win->ws->r->s->c[ev->type == FocusIn ?
|
|
|
|
SWM_S_COLOR_FOCUS : SWM_S_COLOR_UNFOCUS].color);
|
|
|
|
break;
|
|
|
|
default:
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("ignoring focusevent");
|
2009-10-29 11:16:33 +00:00
|
|
|
DNPRINTF(SWM_D_FOCUS, "ignoring focusevent\n");
|
|
|
|
break;
|
|
|
|
}
|
2009-11-06 04:41:28 +00:00
|
|
|
#endif
|
2009-03-04 06:13:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
void
|
2009-10-01 21:08:22 +00:00
|
|
|
mapnotify(XEvent *e)
|
2009-01-13 15:55:13 +00:00
|
|
|
{
|
2009-10-01 21:08:22 +00:00
|
|
|
struct ws_win *win;
|
2009-10-04 04:30:41 +00:00
|
|
|
XMapEvent *ev = &e->xmap;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "mapnotify: window: 0x%lx\n", ev->window);
|
2009-10-01 21:08:22 +00:00
|
|
|
|
2009-10-13 02:28:47 +00:00
|
|
|
win = manage_window(ev->window);
|
2009-10-01 21:08:22 +00:00
|
|
|
if (win)
|
|
|
|
set_win_state(win, NormalState);
|
2012-06-05 23:52:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* focus_win can only set input focus on a mapped window.
|
|
|
|
* make sure the window really has focus since it is just being mapped.
|
|
|
|
*/
|
|
|
|
if (win->ws->focus == win)
|
|
|
|
focus_win(win);
|
2009-10-04 04:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mappingnotify(XEvent *e)
|
|
|
|
{
|
|
|
|
XMappingEvent *ev = &e->xmapping;
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
XRefreshKeyboardMapping(ev);
|
2009-01-17 21:39:22 +00:00
|
|
|
if (ev->request == MappingKeyboard)
|
2009-01-13 15:55:13 +00:00
|
|
|
grabkeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
maprequest(XEvent *e)
|
|
|
|
{
|
2009-09-30 04:21:49 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
struct swm_region *r;
|
2009-01-17 17:23:52 +00:00
|
|
|
XWindowAttributes wa;
|
2009-10-15 20:42:59 +00:00
|
|
|
XMapRequestEvent *ev = &e->xmaprequest;
|
2009-01-17 17:23:52 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "maprequest: window: 0x%lx\n",
|
2009-01-14 05:14:13 +00:00
|
|
|
e->xmaprequest.window);
|
2009-01-15 03:50:26 +00:00
|
|
|
|
2009-01-17 21:39:22 +00:00
|
|
|
if (!XGetWindowAttributes(display, ev->window, &wa))
|
2009-10-05 17:03:47 +00:00
|
|
|
return;
|
2009-01-17 21:39:22 +00:00
|
|
|
if (wa.override_redirect)
|
2009-10-05 17:03:47 +00:00
|
|
|
return;
|
2009-09-29 21:23:59 +00:00
|
|
|
|
2009-10-05 17:03:47 +00:00
|
|
|
win = manage_window(e->xmaprequest.window);
|
|
|
|
if (win == NULL)
|
|
|
|
return; /* can't happen */
|
2009-02-03 21:50:16 +00:00
|
|
|
|
2009-01-16 23:40:01 +00:00
|
|
|
stack();
|
2009-09-29 21:23:59 +00:00
|
|
|
|
|
|
|
/* make new win focused */
|
2009-09-30 04:21:49 +00:00
|
|
|
r = root_to_region(win->wa.root);
|
2009-09-30 21:23:55 +00:00
|
|
|
if (win->ws == r->ws)
|
2011-06-07 20:56:29 +00:00
|
|
|
focus_magic(win);
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
propertynotify(XEvent *e)
|
|
|
|
{
|
2009-01-29 20:27:11 +00:00
|
|
|
struct ws_win *win;
|
|
|
|
XPropertyEvent *ev = &e->xproperty;
|
2012-02-02 07:00:45 +08:00
|
|
|
#ifdef SWM_DEBUG
|
|
|
|
char *name;
|
|
|
|
name = XGetAtomName(display, ev->atom);
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "propertynotify: window: 0x%lx, atom: %s\n",
|
2012-02-02 07:00:45 +08:00
|
|
|
ev->window, name);
|
|
|
|
XFree(name);
|
|
|
|
#endif
|
2009-01-29 20:27:11 +00:00
|
|
|
|
|
|
|
win = find_window(ev->window);
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-06-06 19:52:03 +00:00
|
|
|
if (ev->state == PropertyDelete && ev->atom == a_swm_iconic) {
|
|
|
|
update_iconic(win, 0);
|
|
|
|
XMapRaised(display, win->id);
|
|
|
|
stack();
|
|
|
|
focus_win(win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-29 20:27:11 +00:00
|
|
|
switch (ev->atom) {
|
|
|
|
#if 0
|
2011-12-10 22:20:42 -05:00
|
|
|
case XA_WM_NORMAL_HINTS:
|
2009-01-29 20:27:11 +00:00
|
|
|
long mask;
|
|
|
|
XGetWMNormalHints(display, win->id, &win->sh, &mask);
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("normal hints: flag 0x%x", win->sh.flags);
|
2009-01-29 20:27:11 +00:00
|
|
|
if (win->sh.flags & PMinSize) {
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = win->sh.min_width;
|
|
|
|
HEIGHT(win) = win->sh.min_height;
|
2012-02-02 23:55:19 +00:00
|
|
|
warnx("min %d %d", WIDTH(win), HEIGHT(win));
|
2009-01-29 20:27:11 +00:00
|
|
|
}
|
|
|
|
XMoveResizeWindow(display, win->id,
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win), Y(win), WIDTH(win), HEIGHT(win));
|
2009-01-29 20:27:11 +00:00
|
|
|
#endif
|
2011-12-10 22:20:42 -05:00
|
|
|
case XA_WM_CLASS:
|
|
|
|
case XA_WM_NAME:
|
2012-05-12 22:05:21 +01:00
|
|
|
bar_update();
|
2009-01-29 20:27:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unmapnotify(XEvent *e)
|
|
|
|
{
|
2009-10-15 20:42:59 +00:00
|
|
|
struct ws_win *win;
|
2009-10-01 21:08:22 +00:00
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "unmapnotify: window: 0x%lx\n", e->xunmap.window);
|
2009-10-01 21:08:22 +00:00
|
|
|
|
|
|
|
/* determine if we need to help unmanage this window */
|
|
|
|
win = find_window(e->xunmap.window);
|
|
|
|
if (win == NULL)
|
2009-10-05 17:03:47 +00:00
|
|
|
return;
|
2009-10-01 21:08:22 +00:00
|
|
|
|
|
|
|
if (getstate(e->xunmap.window) == NormalState) {
|
|
|
|
unmanage_window(win);
|
|
|
|
stack();
|
2011-06-09 16:31:58 +00:00
|
|
|
|
|
|
|
/* giant hack for apps that don't destroy transient windows */
|
|
|
|
/* eat a bunch of events to prevent remanaging the window */
|
|
|
|
XEvent cne;
|
|
|
|
while (XCheckWindowEvent(display, e->xunmap.window,
|
|
|
|
EnterWindowMask, &cne))
|
|
|
|
;
|
|
|
|
while (XCheckWindowEvent(display, e->xunmap.window,
|
|
|
|
StructureNotifyMask, &cne))
|
|
|
|
;
|
|
|
|
while (XCheckWindowEvent(display, e->xunmap.window,
|
|
|
|
SubstructureNotifyMask, &cne))
|
|
|
|
;
|
|
|
|
/* resend unmap because we ated it */
|
|
|
|
XUnmapWindow(display, e->xunmap.window);
|
2009-10-01 21:08:22 +00:00
|
|
|
}
|
2011-06-13 18:32:53 +00:00
|
|
|
|
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 19:38:24 +00:00
|
|
|
void
|
|
|
|
visibilitynotify(XEvent *e)
|
|
|
|
{
|
2009-01-19 14:15:31 +00:00
|
|
|
int i;
|
|
|
|
struct swm_region *r;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: 0x%lx\n",
|
2009-01-19 14:15:31 +00:00
|
|
|
e->xvisibility.window);
|
2009-01-19 05:48:11 +00:00
|
|
|
if (e->xvisibility.state == VisibilityUnobscured)
|
2009-08-30 18:16:41 +00:00
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
|
|
|
if (e->xvisibility.window == r->bar_window)
|
2009-01-19 21:11:46 +00:00
|
|
|
bar_update();
|
2009-01-14 19:38:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
void
|
|
|
|
clientmessage(XEvent *e)
|
|
|
|
{
|
|
|
|
XClientMessageEvent *ev;
|
|
|
|
struct ws_win *win;
|
|
|
|
|
|
|
|
ev = &e->xclient;
|
|
|
|
|
|
|
|
win = find_window(ev->window);
|
|
|
|
if (win == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "clientmessage: window: 0x%lx, type: %ld\n",
|
2010-09-16 02:26:45 +00:00
|
|
|
ev->window, ev->message_type);
|
|
|
|
|
|
|
|
if (ev->message_type == ewmh[_NET_ACTIVE_WINDOW].atom) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "clientmessage: _NET_ACTIVE_WINDOW\n");
|
2010-09-16 02:26:45 +00:00
|
|
|
focus_win(win);
|
|
|
|
}
|
|
|
|
if (ev->message_type == ewmh[_NET_CLOSE_WINDOW].atom) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "clientmessage: _NET_CLOSE_WINDOW\n");
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->can_delete)
|
|
|
|
client_msg(win, adelete);
|
|
|
|
else
|
|
|
|
XKillClient(display, win->id);
|
|
|
|
}
|
|
|
|
if (ev->message_type == ewmh[_NET_MOVERESIZE_WINDOW].atom) {
|
2011-06-14 22:20:55 +00:00
|
|
|
DNPRINTF(SWM_D_EVENT,
|
2012-01-29 01:29:31 +08:00
|
|
|
"clientmessage: _NET_MOVERESIZE_WINDOW\n");
|
2010-09-16 02:26:45 +00:00
|
|
|
if (win->floating) {
|
|
|
|
if (ev->data.l[0] & (1<<8)) /* x */
|
2012-01-29 01:29:31 +08:00
|
|
|
X(win) = ev->data.l[1];
|
2010-09-16 02:26:45 +00:00
|
|
|
if (ev->data.l[0] & (1<<9)) /* y */
|
2012-01-29 01:29:31 +08:00
|
|
|
Y(win) = ev->data.l[2];
|
2010-09-16 02:26:45 +00:00
|
|
|
if (ev->data.l[0] & (1<<10)) /* width */
|
2012-01-29 01:29:31 +08:00
|
|
|
WIDTH(win) = ev->data.l[3];
|
2010-09-16 02:26:45 +00:00
|
|
|
if (ev->data.l[0] & (1<<11)) /* height */
|
2012-01-29 01:29:31 +08:00
|
|
|
HEIGHT(win) = ev->data.l[4];
|
|
|
|
|
|
|
|
update_window(win);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO: Change stack sizes */
|
2012-01-29 01:29:31 +08:00
|
|
|
/* notify no change was made. */
|
|
|
|
config_win(win, NULL);
|
2010-09-16 02:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ev->message_type == ewmh[_NET_WM_STATE].atom) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "clientmessage: _NET_WM_STATE\n");
|
2010-09-16 02:26:45 +00:00
|
|
|
ewmh_update_win_state(win, ev->data.l[1], ev->data.l[0]);
|
|
|
|
if (ev->data.l[2])
|
2011-06-14 22:20:55 +00:00
|
|
|
ewmh_update_win_state(win, ev->data.l[2],
|
|
|
|
ev->data.l[0]);
|
2010-09-16 02:26:45 +00:00
|
|
|
|
|
|
|
stack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
int
|
|
|
|
xerror_start(Display *d, XErrorEvent *ee)
|
|
|
|
{
|
|
|
|
other_wm = 1;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xerror(Display *d, XErrorEvent *ee)
|
|
|
|
{
|
2012-02-02 23:55:19 +00:00
|
|
|
/* warnx("error: %p %p", display, ee); */
|
2009-01-13 15:55:13 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
active_wm(void)
|
|
|
|
{
|
|
|
|
other_wm = 0;
|
|
|
|
xerrorxlib = XSetErrorHandler(xerror_start);
|
|
|
|
|
|
|
|
/* this causes an error if some other window manager is running */
|
|
|
|
XSelectInput(display, DefaultRootWindow(display),
|
|
|
|
SubstructureRedirectMask);
|
|
|
|
XSync(display, False);
|
2009-01-17 21:39:22 +00:00
|
|
|
if (other_wm)
|
2009-01-13 15:55:13 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
XSetErrorHandler(xerror);
|
|
|
|
XSync(display, False);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-02-01 11:59:40 +00:00
|
|
|
void
|
2009-02-03 05:08:27 +00:00
|
|
|
new_region(struct swm_screen *s, int x, int y, int w, int h)
|
2009-01-19 05:48:11 +00:00
|
|
|
{
|
2009-02-01 11:59:40 +00:00
|
|
|
struct swm_region *r, *n;
|
2009-02-03 06:38:25 +00:00
|
|
|
struct workspace *ws = NULL;
|
2009-02-01 11:59:40 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DNPRINTF(SWM_D_MISC, "new region: screen[%d]:%dx%d+%d+%d\n",
|
|
|
|
s->idx, w, h, x, y);
|
|
|
|
|
|
|
|
/* remove any conflicting regions */
|
|
|
|
n = TAILQ_FIRST(&s->rl);
|
|
|
|
while (n) {
|
|
|
|
r = n;
|
|
|
|
n = TAILQ_NEXT(r, entry);
|
|
|
|
if (X(r) < (x + w) &&
|
|
|
|
(X(r) + WIDTH(r)) > x &&
|
|
|
|
Y(r) < (y + h) &&
|
|
|
|
(Y(r) + HEIGHT(r)) > y) {
|
2011-06-03 20:55:02 +00:00
|
|
|
if (r->ws->r != NULL)
|
2010-07-01 21:06:18 +00:00
|
|
|
r->ws->old_r = r->ws->r;
|
|
|
|
r->ws->r = NULL;
|
2009-02-03 05:08:27 +00:00
|
|
|
XDestroyWindow(display, r->bar_window);
|
|
|
|
TAILQ_REMOVE(&s->rl, r, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&s->orl, r, entry);
|
2009-02-01 11:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
/* search old regions for one to reuse */
|
|
|
|
|
|
|
|
/* size + location match */
|
|
|
|
TAILQ_FOREACH(r, &s->orl, entry)
|
|
|
|
if (X(r) == x && Y(r) == y &&
|
|
|
|
HEIGHT(r) == h && WIDTH(r) == w)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* size match */
|
|
|
|
TAILQ_FOREACH(r, &s->orl, entry)
|
|
|
|
if (HEIGHT(r) == h && WIDTH(r) == w)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (r != NULL) {
|
|
|
|
TAILQ_REMOVE(&s->orl, r, entry);
|
|
|
|
/* try to use old region's workspace */
|
|
|
|
if (r->ws->r == NULL)
|
|
|
|
ws = r->ws;
|
|
|
|
} else
|
|
|
|
if ((r = calloc(1, sizeof(struct swm_region))) == NULL)
|
2012-01-29 01:29:31 +08:00
|
|
|
err(1, "new_region: calloc: failed to allocate memory "
|
|
|
|
"for screen");
|
2009-02-03 05:08:27 +00:00
|
|
|
|
|
|
|
/* if we don't have a workspace already, find one */
|
2009-02-01 11:59:40 +00:00
|
|
|
if (ws == NULL) {
|
2012-04-08 01:59:41 +08:00
|
|
|
for (i = 0; i < workspace_limit; i++)
|
2009-02-01 11:59:40 +00:00
|
|
|
if (s->ws[i].r == NULL) {
|
|
|
|
ws = &s->ws[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-02-03 06:45:53 +00:00
|
|
|
if (ws == NULL)
|
2012-01-29 01:29:31 +08:00
|
|
|
errx(1, "new_region: no free workspaces");
|
2009-02-03 06:45:53 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
X(r) = x;
|
|
|
|
Y(r) = y;
|
|
|
|
WIDTH(r) = w;
|
|
|
|
HEIGHT(r) = h;
|
|
|
|
r->s = s;
|
|
|
|
r->ws = ws;
|
2010-07-01 19:01:15 +00:00
|
|
|
r->ws_prior = NULL;
|
2009-01-19 05:48:11 +00:00
|
|
|
ws->r = r;
|
2010-07-07 15:40:29 +00:00
|
|
|
outputs++;
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_INSERT_TAIL(&s->rl, r, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-03 05:08:27 +00:00
|
|
|
scan_xrandr(int i)
|
2009-01-19 05:48:11 +00:00
|
|
|
{
|
2009-01-19 14:15:31 +00:00
|
|
|
#ifdef SWM_XRR_HAS_CRTC
|
2009-01-19 14:59:29 +00:00
|
|
|
XRRCrtcInfo *ci;
|
|
|
|
XRRScreenResources *sr;
|
2009-01-19 14:15:31 +00:00
|
|
|
int c;
|
2009-02-03 06:45:53 +00:00
|
|
|
int ncrtc = 0;
|
2009-01-19 14:15:31 +00:00
|
|
|
#endif /* SWM_XRR_HAS_CRTC */
|
2009-02-03 05:08:27 +00:00
|
|
|
struct swm_region *r;
|
|
|
|
|
|
|
|
|
2009-02-03 06:38:25 +00:00
|
|
|
if (i >= ScreenCount(display))
|
2012-01-29 01:29:31 +08:00
|
|
|
errx(1, "scan_xrandr: invalid screen");
|
2009-02-03 06:38:25 +00:00
|
|
|
|
|
|
|
/* remove any old regions */
|
2009-02-03 05:08:27 +00:00
|
|
|
while ((r = TAILQ_FIRST(&screens[i].rl)) != NULL) {
|
2009-10-01 09:51:31 +00:00
|
|
|
r->ws->old_r = r->ws->r = NULL;
|
2009-02-03 05:08:27 +00:00
|
|
|
XDestroyWindow(display, r->bar_window);
|
|
|
|
TAILQ_REMOVE(&screens[i].rl, r, entry);
|
|
|
|
TAILQ_INSERT_TAIL(&screens[i].orl, r, entry);
|
|
|
|
}
|
2010-07-07 15:40:29 +00:00
|
|
|
outputs = 0;
|
2009-02-03 05:08:27 +00:00
|
|
|
|
|
|
|
/* map virtual screens onto physical screens */
|
|
|
|
#ifdef SWM_XRR_HAS_CRTC
|
|
|
|
if (xrandr_support) {
|
|
|
|
sr = XRRGetScreenResources(display, screens[i].root);
|
|
|
|
if (sr == NULL)
|
|
|
|
new_region(&screens[i], 0, 0,
|
|
|
|
DisplayWidth(display, i),
|
2009-08-30 18:16:41 +00:00
|
|
|
DisplayHeight(display, i));
|
|
|
|
else
|
2009-02-03 05:08:27 +00:00
|
|
|
ncrtc = sr->ncrtc;
|
|
|
|
|
|
|
|
for (c = 0, ci = NULL; c < ncrtc; c++) {
|
|
|
|
ci = XRRGetCrtcInfo(display, sr, sr->crtcs[c]);
|
|
|
|
if (ci->noutput == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ci != NULL && ci->mode == None)
|
|
|
|
new_region(&screens[i], 0, 0,
|
|
|
|
DisplayWidth(display, i),
|
2009-08-30 18:16:41 +00:00
|
|
|
DisplayHeight(display, i));
|
2009-02-03 05:08:27 +00:00
|
|
|
else
|
|
|
|
new_region(&screens[i],
|
|
|
|
ci->x, ci->y, ci->width, ci->height);
|
|
|
|
}
|
|
|
|
if (ci)
|
|
|
|
XRRFreeCrtcInfo(ci);
|
|
|
|
XRRFreeScreenResources(sr);
|
|
|
|
} else
|
|
|
|
#endif /* SWM_XRR_HAS_CRTC */
|
|
|
|
{
|
|
|
|
new_region(&screens[i], 0, 0, DisplayWidth(display, i),
|
2009-08-30 18:16:41 +00:00
|
|
|
DisplayHeight(display, i));
|
2009-02-03 05:08:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-03 06:45:53 +00:00
|
|
|
screenchange(XEvent *e) {
|
2009-02-03 05:08:27 +00:00
|
|
|
XRRScreenChangeNotifyEvent *xe = (XRRScreenChangeNotifyEvent *)e;
|
|
|
|
struct swm_region *r;
|
|
|
|
int i;
|
|
|
|
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENT, "screenchange: root: 0x%lx\n", xe->root);
|
2009-02-03 05:08:27 +00:00
|
|
|
|
|
|
|
if (!XRRUpdateConfiguration(e))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* silly event doesn't include the screen index */
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
|
|
|
if (screens[i].root == xe->root)
|
|
|
|
break;
|
|
|
|
if (i >= ScreenCount(display))
|
2011-12-07 21:53:12 -05:00
|
|
|
errx(1, "screenchange: screen not found");
|
2009-02-03 05:08:27 +00:00
|
|
|
|
|
|
|
/* brute force for now, just re-enumerate the regions */
|
|
|
|
scan_xrandr(i);
|
|
|
|
|
2009-02-12 22:09:44 +00:00
|
|
|
/* add bars to all regions */
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry)
|
|
|
|
bar_setup(r);
|
2009-02-03 05:08:27 +00:00
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-02-03 05:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-16 02:26:45 +00:00
|
|
|
grab_windows(void)
|
2009-02-03 05:08:27 +00:00
|
|
|
{
|
2009-01-19 14:15:31 +00:00
|
|
|
Window d1, d2, *wins = NULL;
|
|
|
|
XWindowAttributes wa;
|
2009-01-19 15:09:04 +00:00
|
|
|
unsigned int no;
|
2010-09-16 02:26:45 +00:00
|
|
|
int i, j;
|
|
|
|
long state, manage;
|
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
if (!XQueryTree(display, screens[i].root, &d1, &d2, &wins, &no))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* attach windows to a region */
|
|
|
|
/* normal windows */
|
|
|
|
for (j = 0; j < no; j++) {
|
|
|
|
if (!XGetWindowAttributes(display, wins[j], &wa) ||
|
|
|
|
wa.override_redirect ||
|
|
|
|
XGetTransientForHint(display, wins[j], &d1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
state = getstate(wins[j]);
|
2011-06-09 16:31:58 +00:00
|
|
|
manage = state == IconicState;
|
2010-09-16 02:26:45 +00:00
|
|
|
if (wa.map_state == IsViewable || manage)
|
|
|
|
manage_window(wins[j]);
|
|
|
|
}
|
|
|
|
/* transient windows */
|
|
|
|
for (j = 0; j < no; j++) {
|
|
|
|
if (!XGetWindowAttributes(display, wins[j], &wa) ||
|
|
|
|
wa.override_redirect)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
state = getstate(wins[j]);
|
2011-06-09 16:31:58 +00:00
|
|
|
manage = state == IconicState;
|
2010-09-16 02:26:45 +00:00
|
|
|
if (XGetTransientForHint(display, wins[j], &d1) &&
|
|
|
|
manage)
|
|
|
|
manage_window(wins[j]);
|
|
|
|
}
|
|
|
|
if (wins) {
|
|
|
|
XFree(wins);
|
|
|
|
wins = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setup_screens(void)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
2009-02-03 05:08:27 +00:00
|
|
|
int errorbase, major, minor;
|
2009-01-19 14:15:31 +00:00
|
|
|
struct workspace *ws;
|
2012-02-02 07:00:45 +08:00
|
|
|
XGCValues gcv;
|
2009-01-19 05:48:11 +00:00
|
|
|
|
|
|
|
if ((screens = calloc(ScreenCount(display),
|
|
|
|
sizeof(struct swm_screen))) == NULL)
|
2012-01-29 01:29:31 +08:00
|
|
|
err(1, "setup_screens: calloc: failed to allocate memory for "
|
|
|
|
"screens");
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
/* initial Xrandr setup */
|
|
|
|
xrandr_support = XRRQueryExtension(display,
|
|
|
|
&xrandr_eventbase, &errorbase);
|
|
|
|
if (xrandr_support)
|
|
|
|
if (XRRQueryVersion(display, &major, &minor) && major < 1)
|
2009-08-30 18:16:41 +00:00
|
|
|
xrandr_support = 0;
|
2009-01-23 01:01:48 +00:00
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
/* map physical screens */
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_WS, "setup_screens: init screen: %d\n", i);
|
2009-01-19 05:48:11 +00:00
|
|
|
screens[i].idx = i;
|
|
|
|
TAILQ_INIT(&screens[i].rl);
|
2009-02-03 05:08:27 +00:00
|
|
|
TAILQ_INIT(&screens[i].orl);
|
2009-01-19 05:48:11 +00:00
|
|
|
screens[i].root = RootWindow(display, i);
|
|
|
|
|
|
|
|
/* set default colors */
|
2009-01-22 06:21:23 +00:00
|
|
|
setscreencolor("red", i + 1, SWM_S_COLOR_FOCUS);
|
|
|
|
setscreencolor("rgb:88/88/88", i + 1, SWM_S_COLOR_UNFOCUS);
|
|
|
|
setscreencolor("rgb:00/80/80", i + 1, SWM_S_COLOR_BAR_BORDER);
|
|
|
|
setscreencolor("black", i + 1, SWM_S_COLOR_BAR);
|
|
|
|
setscreencolor("rgb:a0/a0/a0", i + 1, SWM_S_COLOR_BAR_FONT);
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
/* create graphics context on screen with default font color */
|
|
|
|
screens[i].bar_gc = XCreateGC(display, screens[i].root, 0,
|
|
|
|
&gcv);
|
|
|
|
|
|
|
|
XSetForeground(display, screens[i].bar_gc,
|
|
|
|
screens[i].c[SWM_S_COLOR_BAR_FONT].color);
|
|
|
|
|
2010-07-01 19:49:21 +00:00
|
|
|
/* set default cursor */
|
|
|
|
XDefineCursor(display, screens[i].root,
|
|
|
|
XCreateFontCursor(display, XC_left_ptr));
|
|
|
|
|
2009-01-19 05:48:11 +00:00
|
|
|
/* init all workspaces */
|
2009-02-03 05:08:27 +00:00
|
|
|
/* XXX these should be dynamically allocated too */
|
2012-04-20 14:18:21 +08:00
|
|
|
for (j = 0; j < SWM_WS_MAX; j++) {
|
2009-01-19 14:15:31 +00:00
|
|
|
ws = &screens[i].ws[j];
|
2009-01-19 05:48:11 +00:00
|
|
|
ws->idx = j;
|
2011-11-28 23:25:46 -05:00
|
|
|
ws->name = NULL;
|
2009-01-19 05:48:11 +00:00
|
|
|
ws->focus = NULL;
|
|
|
|
ws->r = NULL;
|
2009-10-01 09:51:31 +00:00
|
|
|
ws->old_r = NULL;
|
2009-01-19 05:48:11 +00:00
|
|
|
TAILQ_INIT(&ws->winlist);
|
2009-10-13 02:28:47 +00:00
|
|
|
TAILQ_INIT(&ws->unmanagedlist);
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-01-19 15:09:04 +00:00
|
|
|
for (k = 0; layouts[k].l_stack != NULL; k++)
|
2009-01-20 05:37:45 +00:00
|
|
|
if (layouts[k].l_config != NULL)
|
|
|
|
layouts[k].l_config(ws,
|
|
|
|
SWM_ARG_ID_STACKINIT);
|
2009-01-19 05:48:11 +00:00
|
|
|
ws->cur_layout = &layouts[0];
|
2011-07-19 21:28:15 +00:00
|
|
|
ws->cur_layout->l_string(ws);
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 06:45:53 +00:00
|
|
|
scan_xrandr(i);
|
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
if (xrandr_support)
|
|
|
|
XRRSelectInput(display, screens[i].root,
|
|
|
|
RRScreenChangeNotifyMask);
|
2009-01-19 05:48:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-04 06:05:57 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
void
|
|
|
|
setup_globals(void)
|
|
|
|
{
|
2012-02-02 07:00:45 +08:00
|
|
|
if ((bar_fonts = strdup(SWM_BAR_FONTS)) == NULL)
|
|
|
|
err(1, "setup_globals: strdup: failed to allocate memory.");
|
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
if ((spawn_term[0] = strdup("xterm")) == NULL)
|
2012-02-02 07:00:45 +08:00
|
|
|
err(1, "setup_globals: strdup: failed to allocate memory.");
|
|
|
|
|
2010-01-13 21:48:35 +00:00
|
|
|
if ((clock_format = strdup("%a %b %d %R %Z %Y")) == NULL)
|
2012-02-02 07:00:45 +08:00
|
|
|
err(1, "setup_globals: strdup: failed to allocate memory.");
|
2009-09-12 21:32:21 +00:00
|
|
|
}
|
2009-01-19 05:48:11 +00:00
|
|
|
|
2009-02-15 23:23:24 +00:00
|
|
|
void
|
|
|
|
workaround(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
Atom netwmcheck, netwmname, utf8_string;
|
2010-09-16 02:26:45 +00:00
|
|
|
Window root, win;
|
2009-02-15 23:23:24 +00:00
|
|
|
|
|
|
|
/* work around sun jdk bugs, code from wmname */
|
|
|
|
netwmcheck = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
|
|
|
|
netwmname = XInternAtom(display, "_NET_WM_NAME", False);
|
|
|
|
utf8_string = XInternAtom(display, "UTF8_STRING", False);
|
|
|
|
for (i = 0; i < ScreenCount(display); i++) {
|
|
|
|
root = screens[i].root;
|
2010-09-16 02:26:45 +00:00
|
|
|
win = XCreateSimpleWindow(display,root, 0, 0, 1, 1, 0,
|
|
|
|
screens[i].c[SWM_S_COLOR_UNFOCUS].color,
|
|
|
|
screens[i].c[SWM_S_COLOR_UNFOCUS].color);
|
|
|
|
|
2009-02-15 23:23:24 +00:00
|
|
|
XChangeProperty(display, root, netwmcheck, XA_WINDOW, 32,
|
2012-05-12 21:28:49 +01:00
|
|
|
PropModeReplace, (unsigned char *)&win, 1);
|
2010-09-16 02:26:45 +00:00
|
|
|
XChangeProperty(display, win, netwmcheck, XA_WINDOW, 32,
|
2012-05-12 21:28:49 +01:00
|
|
|
PropModeReplace, (unsigned char *)&win, 1);
|
2010-09-16 02:26:45 +00:00
|
|
|
XChangeProperty(display, win, netwmname, utf8_string, 8,
|
|
|
|
PropModeReplace, (unsigned char*)"LG3D", strlen("LG3D"));
|
2009-02-15 23:23:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2009-09-29 18:59:09 +00:00
|
|
|
struct swm_region *r, *rr;
|
|
|
|
struct ws_win *winfocus = NULL;
|
2009-10-10 23:24:55 +00:00
|
|
|
struct timeval tv;
|
2009-10-15 20:42:59 +00:00
|
|
|
union arg a;
|
2009-01-14 17:10:52 +00:00
|
|
|
char conf[PATH_MAX], *cfile = NULL;
|
|
|
|
struct stat sb;
|
2009-01-13 15:55:13 +00:00
|
|
|
XEvent e;
|
2009-02-10 04:40:29 +00:00
|
|
|
int xfd, i;
|
2009-01-19 19:27:36 +00:00
|
|
|
fd_set rd;
|
2010-07-05 21:55:38 +00:00
|
|
|
struct sigaction sact;
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-01-17 17:23:52 +00:00
|
|
|
start_argv = argv;
|
2012-02-15 14:09:13 -06:00
|
|
|
warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION, buildstr);
|
2011-11-28 09:50:50 -06:00
|
|
|
if (!setlocale(LC_CTYPE, "") || !setlocale(LC_TIME, "") ||
|
|
|
|
!XSupportsLocale())
|
2009-01-13 15:55:13 +00:00
|
|
|
warnx("no locale support");
|
|
|
|
|
2012-02-02 07:00:45 +08:00
|
|
|
if (!X_HAVE_UTF8_STRING)
|
|
|
|
warnx("no UTF-8 support");
|
|
|
|
|
2009-01-17 21:39:22 +00:00
|
|
|
if (!(display = XOpenDisplay(0)))
|
2009-01-13 15:55:13 +00:00
|
|
|
errx(1, "can not open display");
|
|
|
|
|
|
|
|
if (active_wm())
|
|
|
|
errx(1, "other wm running");
|
|
|
|
|
2010-07-05 21:55:38 +00:00
|
|
|
/* handle some signals */
|
|
|
|
bzero(&sact, sizeof(sact));
|
|
|
|
sigemptyset(&sact.sa_mask);
|
|
|
|
sact.sa_flags = 0;
|
|
|
|
sact.sa_handler = sighdlr;
|
|
|
|
sigaction(SIGINT, &sact, NULL);
|
|
|
|
sigaction(SIGQUIT, &sact, NULL);
|
|
|
|
sigaction(SIGTERM, &sact, NULL);
|
|
|
|
sigaction(SIGHUP, &sact, NULL);
|
|
|
|
|
|
|
|
sact.sa_handler = sighdlr;
|
|
|
|
sact.sa_flags = SA_NOCLDSTOP;
|
|
|
|
sigaction(SIGCHLD, &sact, NULL);
|
2009-09-29 14:25:40 +00:00
|
|
|
|
2009-01-17 19:57:48 +00:00
|
|
|
astate = XInternAtom(display, "WM_STATE", False);
|
2009-02-10 18:16:10 +00:00
|
|
|
aprot = XInternAtom(display, "WM_PROTOCOLS", False);
|
|
|
|
adelete = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
2009-10-07 02:38:38 +00:00
|
|
|
takefocus = XInternAtom(display, "WM_TAKE_FOCUS", False);
|
2011-06-06 19:52:03 +00:00
|
|
|
a_wmname = XInternAtom(display, "WM_NAME", False);
|
2012-01-15 14:53:00 -05:00
|
|
|
a_netwmname = XInternAtom(display, "_NET_WM_NAME", False);
|
2011-06-06 19:52:03 +00:00
|
|
|
a_utf8_string = XInternAtom(display, "UTF8_STRING", False);
|
|
|
|
a_string = XInternAtom(display, "STRING", False);
|
|
|
|
a_swm_iconic = XInternAtom(display, "_SWM_ICONIC", False);
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-01-14 19:08:56 +00:00
|
|
|
/* look for local and global conf file */
|
2009-01-14 17:10:52 +00:00
|
|
|
pwd = getpwuid(getuid());
|
|
|
|
if (pwd == NULL)
|
2012-01-29 01:29:31 +08:00
|
|
|
errx(1, "invalid user: %d", getuid());
|
2009-01-14 17:10:52 +00:00
|
|
|
|
2009-09-12 21:32:21 +00:00
|
|
|
setup_globals();
|
2012-02-02 07:00:45 +08:00
|
|
|
setup_screens();
|
2009-03-10 01:32:06 +00:00
|
|
|
setup_keys();
|
2009-05-25 22:04:56 +00:00
|
|
|
setup_quirks();
|
2009-09-12 21:32:21 +00:00
|
|
|
setup_spawn();
|
2009-01-20 06:16:05 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
/* load config */
|
2012-02-15 16:14:56 -06:00
|
|
|
for (i = 0; ; i++) {
|
2012-02-15 17:26:10 -06:00
|
|
|
conf[0] = '\0';
|
2012-02-15 16:14:56 -06:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
/* ~ */
|
|
|
|
snprintf(conf, sizeof conf, "%s/.%s",
|
|
|
|
pwd->pw_dir, SWM_CONF_FILE);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* global */
|
|
|
|
snprintf(conf, sizeof conf, "/etc/%s",
|
|
|
|
SWM_CONF_FILE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* ~ compat */
|
|
|
|
snprintf(conf, sizeof conf, "%s/.%s",
|
|
|
|
pwd->pw_dir, SWM_CONF_FILE_OLD);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* global compat */
|
|
|
|
snprintf(conf, sizeof conf, "/etc/%s",
|
|
|
|
SWM_CONF_FILE_OLD);
|
|
|
|
break;
|
|
|
|
default:
|
2012-02-15 17:26:10 -06:00
|
|
|
goto noconfig;
|
2012-02-15 16:14:56 -06:00
|
|
|
}
|
2012-02-15 17:26:10 -06:00
|
|
|
|
|
|
|
if (strlen(conf) && stat(conf, &sb) != -1)
|
|
|
|
if (S_ISREG(sb.st_mode)) {
|
|
|
|
cfile = conf;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-14 17:10:52 +00:00
|
|
|
}
|
2012-02-15 17:26:10 -06:00
|
|
|
noconfig:
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
/* load conf (if any) and refresh font color in bar graphics contexts */
|
|
|
|
if (cfile && conf_load(cfile, SWM_CONF_DEFAULT) == 0)
|
|
|
|
for (i = 0; i < ScreenCount(display); ++i)
|
|
|
|
XSetForeground(display, screens[i].bar_gc,
|
|
|
|
screens[i].c[SWM_S_COLOR_BAR_FONT].color);
|
2009-02-10 04:40:29 +00:00
|
|
|
|
2010-09-16 02:26:45 +00:00
|
|
|
setup_ewmh();
|
|
|
|
/* set some values to work around bad programs */
|
|
|
|
workaround();
|
|
|
|
/* grab existing windows (before we build the bars) */
|
|
|
|
grab_windows();
|
|
|
|
|
2011-06-23 02:15:53 +00:00
|
|
|
if (getenv("SWM_STARTED") == NULL)
|
|
|
|
setenv("SWM_STARTED", "YES", 1);
|
|
|
|
|
2009-02-10 04:40:29 +00:00
|
|
|
/* setup all bars */
|
|
|
|
for (i = 0; i < ScreenCount(display); i++)
|
2009-09-29 14:25:40 +00:00
|
|
|
TAILQ_FOREACH(r, &screens[i].rl, entry) {
|
|
|
|
if (winfocus == NULL)
|
|
|
|
winfocus = TAILQ_FIRST(&r->ws->winlist);
|
2009-02-10 04:40:29 +00:00
|
|
|
bar_setup(r);
|
2009-09-29 14:25:40 +00:00
|
|
|
}
|
2009-01-14 04:44:58 +00:00
|
|
|
|
2009-11-06 04:41:28 +00:00
|
|
|
unfocus_all();
|
|
|
|
|
2009-01-13 15:55:13 +00:00
|
|
|
grabkeys();
|
2009-01-15 02:14:08 +00:00
|
|
|
stack();
|
2011-06-10 20:58:47 +00:00
|
|
|
if (focus_mode == SWM_FOCUS_DEFAULT)
|
|
|
|
drain_enter_notify();
|
2009-01-13 15:55:13 +00:00
|
|
|
|
2009-01-19 19:27:36 +00:00
|
|
|
xfd = ConnectionNumber(display);
|
2009-01-13 15:55:13 +00:00
|
|
|
while (running) {
|
2009-02-03 06:38:25 +00:00
|
|
|
while (XPending(display)) {
|
2009-01-19 19:27:36 +00:00
|
|
|
XNextEvent(display, &e);
|
2009-09-30 17:19:03 +00:00
|
|
|
if (running == 0)
|
|
|
|
goto done;
|
2009-02-03 05:08:27 +00:00
|
|
|
if (e.type < LASTEvent) {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENTQ ,"XEvent: handled: %s, "
|
|
|
|
"window: 0x%lx, type: %s (%d), %d remaining"
|
|
|
|
"\n", YESNO(handler[e.type]),
|
|
|
|
e.xany.window, geteventname(&e),
|
|
|
|
e.type, QLength(display));
|
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
if (handler[e.type])
|
|
|
|
handler[e.type](&e);
|
|
|
|
} else {
|
2012-01-29 01:29:31 +08:00
|
|
|
DNPRINTF(SWM_D_EVENTQ, "XRandr Event: window: "
|
|
|
|
"0x%lx, type: %s (%d)\n", e.xany.window,
|
|
|
|
xrandr_geteventname(&e), e.type);
|
|
|
|
|
2009-02-03 05:08:27 +00:00
|
|
|
switch (e.type - xrandr_eventbase) {
|
|
|
|
case RRScreenChangeNotify:
|
|
|
|
screenchange(&e);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-19 19:27:36 +00:00
|
|
|
}
|
2009-09-29 14:25:40 +00:00
|
|
|
|
|
|
|
/* if we are being restarted go focus on first window */
|
|
|
|
if (winfocus) {
|
2009-10-15 20:42:59 +00:00
|
|
|
rr = winfocus->ws->r;
|
|
|
|
if (rr == NULL) {
|
|
|
|
/* not a visible window */
|
|
|
|
winfocus = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-30 17:19:03 +00:00
|
|
|
/* move pointer to first screen if multi screen */
|
2009-09-29 18:59:09 +00:00
|
|
|
if (ScreenCount(display) > 1 || outputs > 1)
|
|
|
|
XWarpPointer(display, None, rr->s[0].root,
|
2012-01-29 01:29:31 +08:00
|
|
|
0, 0, 0, 0, X(rr),
|
|
|
|
Y(rr) + (bar_enabled ? bar_height : 0));
|
2009-09-29 18:59:09 +00:00
|
|
|
|
2009-10-15 20:42:59 +00:00
|
|
|
a.id = SWM_ARG_ID_FOCUSCUR;
|
|
|
|
focus(rr, &a);
|
2009-09-29 14:25:40 +00:00
|
|
|
winfocus = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
FD_ZERO(&rd);
|
|
|
|
FD_SET(xfd, &rd);
|
2009-10-10 23:24:55 +00:00
|
|
|
tv.tv_sec = 1;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
if (select(xfd + 1, &rd, NULL, NULL, &tv) == -1)
|
2009-09-29 14:25:40 +00:00
|
|
|
if (errno != EINTR)
|
2009-09-30 17:19:03 +00:00
|
|
|
DNPRINTF(SWM_D_MISC, "select failed");
|
2010-07-03 22:41:34 +00:00
|
|
|
if (restart_wm == 1)
|
|
|
|
restart(NULL, NULL);
|
2011-06-06 19:52:03 +00:00
|
|
|
if (search_resp == 1)
|
|
|
|
search_do_resp();
|
2009-09-30 17:19:03 +00:00
|
|
|
if (running == 0)
|
|
|
|
goto done;
|
2009-09-29 14:25:40 +00:00
|
|
|
if (bar_alarm) {
|
|
|
|
bar_alarm = 0;
|
|
|
|
bar_update();
|
|
|
|
}
|
2009-01-13 15:55:13 +00:00
|
|
|
}
|
2009-09-30 17:19:03 +00:00
|
|
|
done:
|
2010-09-16 02:26:45 +00:00
|
|
|
teardown_ewmh();
|
2009-09-29 14:25:40 +00:00
|
|
|
bar_extra_stop();
|
2012-02-02 07:00:45 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ScreenCount(display); ++i)
|
|
|
|
if (screens[i].bar_gc != NULL)
|
|
|
|
XFreeGC(display, screens[i].bar_gc);
|
|
|
|
|
|
|
|
XFreeFontSet(display, bar_fs);
|
2009-01-13 15:55:13 +00:00
|
|
|
XCloseDisplay(display);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|