summaryrefslogtreecommitdiff
path: root/mcwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'mcwm.c')
-rw-r--r--mcwm.c110
1 files changed, 77 insertions, 33 deletions
diff --git a/mcwm.c b/mcwm.c
index bf9ff26..30ea9b7 100644
--- a/mcwm.c
+++ b/mcwm.c
@@ -43,6 +43,7 @@
#include <xcb/xcb_keysyms.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_icccm.h>
+#include <xcb/xcb_xrm.h>
#include <X11/keysym.h>
@@ -86,15 +87,20 @@
*/
#define MCWM_TABBING 4
-/* Number of workspaces. */
+/* Default number of workspaces. */
#define WORKSPACES 10
+/* Maximum number of workspaces (wslist needs update if increased). */
+#define MAX_WORKSPACES 100
+
/* Value in WM hint which means this window is fixed on all workspaces. */
#define NET_WM_FIXED 0xffffffff
/* This means we didn't get any window hint at all. */
#define MCWM_NOWS 0xfffffffe
+long workspaces = WORKSPACES;
+
/* Types. */
@@ -172,7 +178,7 @@ struct client
bool fixed; /* Visible on all workspaces? */
struct monitor *monitor; /* The physical output this window is on. */
struct item *winitem; /* Pointer to our place in global windows list. */
- struct item *wsitem[WORKSPACES]; /* Pointer to our place in every
+ struct item *wsitem[MAX_WORKSPACES]; /* Pointer to our place in every
* workspace window list. */
};
@@ -210,18 +216,18 @@ int mode = 0; /* Internal mode, such as move or resize */
* Workspace list: Every workspace has a list of all visible
* windows.
*/
-struct item *wslist[WORKSPACES] =
+struct item *wslist[MAX_WORKSPACES] =
{
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
/* Shortcut key type and initializiation. */
@@ -322,6 +328,7 @@ static xcb_keycode_t keysymtokeycode(xcb_keysym_t keysym,
static int setupkeys(void);
static int setupscreen(void);
static int setuprandr(void);
+static void setupworkspaces(void);
static void getrandr(void);
static void getoutputs(xcb_randr_output_t *outputs, int len,
xcb_timestamp_t timestamp);
@@ -371,6 +378,7 @@ static void configwin(xcb_window_t win, uint16_t mask, struct winconf wc);
static void configurerequest(xcb_configure_request_event_t *e);
static void events(void);
static void printhelp(void);
+static void printversion(void);
static void sigcatch(int sig);
static xcb_atom_t getatom(char *atom_name);
@@ -701,7 +709,7 @@ void fixwindow(struct client *client, bool setcolour)
}
/* Delete from all workspace lists except current. */
- for (ws = 0; ws < WORKSPACES; ws ++)
+ for (ws = 0; ws < workspaces; ws ++)
{
if (ws != curws)
{
@@ -722,7 +730,7 @@ void fixwindow(struct client *client, bool setcolour)
setwmdesktop(client->id, NET_WM_FIXED);
/* Add window to all workspace lists. */
- for (ws = 0; ws < WORKSPACES; ws ++)
+ for (ws = 0; ws < workspaces; ws ++)
{
if (ws != curws)
{
@@ -785,7 +793,7 @@ void forgetclient(struct client *client)
* Note that it's OK to be on several workspaces at once even if
* you're not fixed.
*/
- for (ws = 0; ws < WORKSPACES; ws ++)
+ for (ws = 0; ws < workspaces; ws ++)
{
if (NULL != client->wsitem[ws])
{
@@ -827,7 +835,7 @@ void forgetwin(xcb_window_t win)
* to. Note that it's OK to be on several workspaces at
* once.
*/
- for (ws = 0; ws < WORKSPACES; ws ++)
+ for (ws = 0; ws < workspaces; ws ++)
{
PDEBUG("Looking in ws #%d.\n", ws);
if (NULL == client->wsitem[ws])
@@ -1142,7 +1150,7 @@ struct client *setupwin(xcb_window_t win)
client->winitem = item;
- for (ws = 0; ws < WORKSPACES; ws ++)
+ for (ws = 0; ws < workspaces; ws ++)
{
client->wsitem[ws] = NULL;
}
@@ -1411,7 +1419,7 @@ int setupscreen(void)
/* Add to all other workspaces. */
fixwindow(client, false);
}
- else if (MCWM_NOWS != ws && ws < WORKSPACES)
+ else if (MCWM_NOWS != ws && ws < workspaces)
{
addtoworkspace(client, ws);
/* If it's not our current workspace, hide it. */
@@ -1494,6 +1502,29 @@ int setuprandr(void)
return base;
}
+
+/*
+ * Set user's desired number of workspaces from Xresource.
+ * TODO Allocate structures to merely occupy their needed size.
+ */
+void setupworkspaces(void)
+{
+ xcb_xrm_database_t *xrm_db = xcb_xrm_database_from_default(conn);
+ long value;
+ if (! xcb_xrm_resource_get_long(xrm_db, "MCwm.workspaces", NULL, &value)) {
+ PDEBUG("Xresource configuring workspace count: %ld\n", value);
+ if (value > 0 && value <= MAX_WORKSPACES) {
+ workspaces = value;
+ } else {
+ fprintf (stderr, "MCwm.workspaces must be a natural number less than "
+ "or equal to %d.\n", MAX_WORKSPACES);
+ exit(1);
+ }
+ } else {
+ PDEBUG("Xresource configuring workspace count is not set.\n");
+ }
+}
+
/*
* Get RANDR resources and figure out how many outputs there are.
*/
@@ -3259,43 +3290,43 @@ void handle_keypress(xcb_key_press_event_t *ev)
break;
case KEY_1:
- changeworkspace(0);
+ changeworkspace(0 % workspaces);
break;
case KEY_2:
- changeworkspace(1);
+ changeworkspace(1 % workspaces);
break;
case KEY_3:
- changeworkspace(2);
+ changeworkspace(2 % workspaces);
break;
case KEY_4:
- changeworkspace(3);
+ changeworkspace(3 % workspaces);
break;
case KEY_5:
- changeworkspace(4);
+ changeworkspace(4 % workspaces);
break;
case KEY_6:
- changeworkspace(5);
+ changeworkspace(5 % workspaces);
break;
case KEY_7:
- changeworkspace(6);
+ changeworkspace(6 % workspaces);
break;
case KEY_8:
- changeworkspace(7);
+ changeworkspace(7 % workspaces);
break;
case KEY_9:
- changeworkspace(8);
+ changeworkspace(8 % workspaces);
break;
case KEY_0:
- changeworkspace(9);
+ changeworkspace(9 % workspaces);
break;
case KEY_Y:
@@ -3340,12 +3371,12 @@ void handle_keypress(xcb_key_press_event_t *ev)
}
else
{
- changeworkspace(WORKSPACES - 1);
+ changeworkspace(workspaces - 1);
}
break;
case KEY_NEXTWS:
- changeworkspace((curws + 1) % WORKSPACES);
+ changeworkspace((curws + 1) % workspaces);
break;
default:
@@ -4271,7 +4302,7 @@ void events(void)
void printhelp(void)
{
printf("mcwm: Usage: mcwm [-b] [-s snapmargin] [-t terminal-program] "
- "[-f colour] [-u colour] [-x colour] \n");
+ "[-f colour] [-u colour] [-x colour] -V\n");
printf(" -b means draw no borders\n");
printf(" -s snapmargin in pixels\n");
printf(" -t urxvt will start urxvt when MODKEY + Return is pressed\n");
@@ -4279,6 +4310,12 @@ void printhelp(void)
"to a named color.\n");
printf(" -u colour sets colour for unfocused window borders.\n");
printf(" -x color sets colour for fixed window borders.\n");
+ printf(" -V merely prints mcwm's version string and exits immediatly.\n");
+}
+
+void printversion(void)
+{
+ printf("mcwm version: %s\n", VERSION);
}
void sigcatch(int sig)
@@ -4358,7 +4395,7 @@ int main(int argc, char **argv)
while (1)
{
- ch = getopt(argc, argv, "b:s:it:f:u:x:");
+ ch = getopt(argc, argv, "b:s:it:f:u:x:V");
if (-1 == ch)
{
@@ -4398,6 +4435,11 @@ int main(int argc, char **argv)
fixedcol = optarg;
break;
+ case 'V':
+ printversion();
+ exit(0);
+ break;
+
default:
printhelp();
exit(0);
@@ -4415,6 +4457,8 @@ int main(int argc, char **argv)
exit(1);
}
+ setupworkspaces();
+
/* Find our screen. */
iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
for (int i = 0; i < scrno; ++ i)