Skip to content

Instantly share code, notes, and snippets.

@davidbe
Created December 14, 2011 20:29
Show Gist options
  • Save davidbe/1478365 to your computer and use it in GitHub Desktop.
Save davidbe/1478365 to your computer and use it in GitHub Desktop.
mcwm diffs by davidbe
*****************************************************************************************
*****************************************************************************************
compile with xcb_util 0.3.8
*****************************************************************************************
*****************************************************************************************
----------------------------------- Makefile -----------------------------------
index 442047a..54d45e0 100644
@@ -6,7 +6,7 @@ DISTFILES=LICENSE Makefile NEWS README TODO WISHLIST mcwm.man $(SRC)
CC=gcc
CFLAGS=-g -std=c99 -Wall -Wextra -O2 -I/usr/local/include #-DDEBUG #-DDMALLOC
LDFLAGS=-L/usr/local/lib -lxcb -lxcb-randr -lxcb-keysyms -lxcb-icccm \
- -lxcb-atom #-ldmalloc
+ -lxcb-util #-ldmalloc
RM=/bin/rm
PREFIX=/usr/local
------------------------------------ mcwm.c ------------------------------------
index 0613c9f..04a7a41 100644
@@ -45,6 +45,10 @@
#include <X11/keysym.h>
+#include <xcb/xproto.h>
+#include <xcb/xcb_util.h>
+#include <xcb/xcb_ewmh.h>
+
#ifdef DEBUG
#include "events.h"
#endif
@@ -503,7 +507,7 @@ void setwmdesktop(xcb_drawable_t win, uint32_t ws)
PDEBUG("Changing _NET_WM_DESKTOP on window %d to %d\n", win, ws);
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win,
- atom_desktop, CARDINAL, 32, 1,
+ atom_desktop, XCB_ATOM_CARDINAL, 32, 1,
&ws);
}
@@ -521,7 +525,7 @@ int32_t getwmdesktop(xcb_drawable_t win)
uint32_t *wsp;
uint32_t ws;
- cookie = xcb_get_any_property(conn, false, win, atom_desktop,
+ cookie = xcb_get_property(conn, false, win, atom_desktop,XCB_GET_PROPERTY_TYPE_ANY, 0,
sizeof (int32_t));
reply = xcb_get_property_reply(conn, cookie, NULL);
@@ -1136,8 +1140,8 @@ struct client *setupwin(xcb_window_t win)
/*
* Get the window's incremental size step, if any.
*/
- if (!xcb_get_wm_normal_hints_reply(
- conn, xcb_get_wm_normal_hints_unchecked(
+ if (!xcb_icccm_get_wm_normal_hints_reply(
+ conn, xcb_icccm_get_wm_normal_hints_unchecked(
conn, win), &hints, NULL))
{
PDEBUG("Couldn't get size hints.\n");
@@ -1147,25 +1151,25 @@ struct client *setupwin(xcb_window_t win)
* The user specified the position coordinates. Remember that so
* we can use geometry later.
*/
- if (hints.flags & XCB_SIZE_HINT_US_POSITION)
+ if (hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION)
{
client->usercoord = true;
}
- if (hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
+ if (hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
{
client->min_width = hints.min_width;
client->min_height = hints.min_height;
}
- if (hints.flags & XCB_SIZE_HINT_P_MAX_SIZE)
+ if (hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
{
client->max_width = hints.max_width;
client->max_height = hints.max_height;
}
- if (hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)
+ if (hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
{
client->width_inc = hints.width_inc;
client->height_inc = hints.height_inc;
@@ -1174,7 +1178,7 @@ struct client *setupwin(xcb_window_t win)
client->height_inc);
}
- if (hints.flags & XCB_SIZE_HINT_BASE_SIZE)
+ if (hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE)
{
client->base_width = hints.base_width;
client->base_height = hints.base_height;
@@ -2823,7 +2827,7 @@ void botright(void)
void deletewin(void)
{
xcb_get_property_cookie_t cookie;
- xcb_get_wm_protocols_reply_t protocols;
+ xcb_icccm_get_wm_protocols_reply_t protocols;
bool use_delete = false;
uint32_t i;
@@ -2833,14 +2837,14 @@ void deletewin(void)
}
/* Check if WM_DELETE is supported. */
- cookie = xcb_get_wm_protocols_unchecked(conn, focuswin->id, wm_protocols);
- if (xcb_get_wm_protocols_reply(conn, cookie, &protocols, NULL) == 1) {
+ cookie = xcb_icccm_get_wm_protocols_unchecked(conn, focuswin->id, wm_protocols);
+ if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &protocols, NULL) == 1) {
for (i = 0; i < protocols.atoms_len; i++)
if (protocols.atoms[i] == wm_delete_window)
use_delete = true;
}
- xcb_get_wm_protocols_reply_wipe(&protocols);
+ xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
if (use_delete)
{
@@ -4082,9 +4086,50 @@ int main(int argc, char **argv)
conf.fixedcol = getcolor(fixedcol);
/* Get some atoms. */
- atom_desktop = xcb_atom_get(conn, "_NET_WM_DESKTOP");
- wm_delete_window = xcb_atom_get(conn, "WM_DELETE_WINDOW");
- wm_protocols = xcb_atom_get(conn, "WM_PROTOCOLS");
+// atom_desktop = xcb_atom_get(conn, "_NET_WM_DESKTOP");
+// wm_delete_window = xcb_atom_get(conn, "WM_DELETE_WINDOW");
+// wm_protocols = xcb_atom_get(conn, "WM_PROTOCOLS");
+
+ char *atom_name;
+ xcb_intern_atom_cookie_t cookie_desktop;
+ xcb_intern_atom_cookie_t cookie_delete_window;
+ xcb_intern_atom_cookie_t cookie_protocols;
+ xcb_intern_atom_reply_t *rep;
+
+ atom_name = "_NET_WM_DESKTOP";
+ cookie_desktop = xcb_intern_atom (conn,
+ 0,
+ strlen (atom_name),
+ atom_name);
+ rep = xcb_intern_atom_reply (conn,
+ cookie_desktop,
+ NULL);
+ atom_desktop = rep->atom;
+ free (rep);
+
+
+ atom_name = "WM_DELETE_WINDOW";
+ cookie_delete_window = xcb_intern_atom (conn,
+ 0,
+ strlen (atom_name),
+ atom_name);
+ rep = xcb_intern_atom_reply (conn,
+ cookie_delete_window,
+ NULL);
+ wm_delete_window = rep->atom;
+ free (rep);
+
+ atom_name = "WM_PROTOCOLS";
+ cookie_protocols = xcb_intern_atom (conn,
+ 0,
+ strlen (atom_name),
+ atom_name);
+ rep = xcb_intern_atom_reply (conn,
+ cookie_protocols,
+ NULL);
+ wm_protocols = rep->atom;
+ free (rep);
+
/* Check for RANDR extension and configure. */
randrbase = setuprandr();
*****************************************************************************************
*****************************************************************************************
added launcher and workspace switch previous/next
`-> launcher should be removed when xbindkeys get through
*****************************************************************************************
*****************************************************************************************
------------------------------------ mcwm.c ------------------------------------
index 04a7a41..141341b 100644
@@ -127,6 +127,9 @@ typedef enum {
KEY_END,
KEY_PREVSCR,
KEY_NEXTSCR,
+ KEY_PREVWS,
+ KEY_NEXTWS,
+ KEY_LAUNCHER,
KEY_MAX
} key_enum_t;
@@ -255,6 +258,9 @@ struct keys
{ USERKEY_DELETE, 0 },
{ USERKEY_PREVSCREEN, 0 },
{ USERKEY_NEXTSCREEN, 0 },
+ { USERKEY_PREVWS, 0 },
+ { USERKEY_NEXTWS, 0 },
+ { USERKEY_LAUNCHER, 0 }
};
/* All keycodes generating our MODKEY mask. */
@@ -273,6 +279,7 @@ struct conf
{
int borderwidth; /* Do we draw borders? If so, how large? */
char *terminal; /* Path to terminal to start. */
+ char *launcher; /* Path to launcher to start. */
uint32_t focuscol; /* Focused border colour. */
uint32_t unfocuscol; /* Unfocused border colour. */
uint32_t fixedcol; /* Fixed windows border colour. */
@@ -299,6 +306,7 @@ static int32_t getwmdesktop(xcb_drawable_t win);
static void addtoworkspace(struct client *client, uint32_t ws);
static void delfromworkspace(struct client *client, uint32_t ws);
static void changeworkspace(uint32_t ws);
+static void switchws(int32_t dir);
static void fixwindow(struct client *client, bool setcolour);
static uint32_t getcolor(const char *colstr);
static void forgetclient(struct client *client);
@@ -659,6 +667,28 @@ void changeworkspace(uint32_t ws)
curws = ws;
}
+/* changes workspace prev/next */
+void switchws(int32_t dir)
+{
+ int32_t newws;
+
+ PDEBUG("Changing from workspace #%d in dir #%d\n", curws, dir);
+
+ newws = curws + dir;
+
+ if (newws == -1)
+ {
+ newws = 9;
+ }
+
+ if (newws == 10)
+ {
+ newws = 0;
+ }
+
+ changeworkspace(newws);
+}
+
/*
* Fix or unfix a window client from all workspaces. If setcolour is
* set, also change back to ordinary focus colour when unfixing.
@@ -2824,6 +2854,8 @@ void botright(void)
xcb_flush(conn);
}
+
+
void deletewin(void)
{
xcb_get_property_cookie_t cookie;
@@ -2988,6 +3020,10 @@ void handle_keypress(xcb_key_press_event_t *ev)
start(conf.terminal);
break;
+ case KEY_LAUNCHER: /* return */
+ start(conf.launcher);
+ break;
+
case KEY_F: /* f */
fixwindow(focuswin, true);
break;
@@ -3092,6 +3128,14 @@ void handle_keypress(xcb_key_press_event_t *ev)
nextscreen();
break;
+ case KEY_PREVWS:
+ switchws(-1);
+ break;
+
+ case KEY_NEXTWS:
+ switchws(1);
+ break;
+
default:
/* Ignore other keys. */
break;
@@ -4023,6 +4067,7 @@ int main(int argc, char **argv)
conf.borderwidth = BORDERWIDTH;
conf.terminal = TERMINAL;
+ conf.launcher = LAUNCHER;
focuscol = FOCUSCOL;
unfocuscol = UNFOCUSCOL;
fixedcol = FIXEDCOL;
*****************************************************************************************
*****************************************************************************************
added grow top/bot left/right
*****************************************************************************************
*****************************************************************************************
----------------------------------- mcwm.c ------------------------------------
index 141341b..15ff954 100644
@@ -358,6 +358,10 @@ static void topleft(void);
static void topright(void);
static void botleft(void);
static void botright(void);
+static void growtopleft(void);
+static void growtopright(void);
+static void growbotleft(void);
+static void growbotright(void);
static void deletewin(void);
static void prevscreen(void);
static void nextscreen(void);
@@ -2854,6 +2858,179 @@ void botright(void)
xcb_flush(conn);
}
+void growtopleft(void)
+{
+ int16_t pointx;
+ int16_t pointy;
+ int16_t mon_x;
+ int16_t mon_y;
+
+ if (NULL == focuswin)
+ {
+ return;
+ }
+
+ if (NULL == focuswin->monitor)
+ {
+ mon_x = 0;
+ mon_y = 0;
+ }
+ else
+ {
+ mon_x = focuswin->monitor->x;
+ mon_y = focuswin->monitor->y;
+ }
+
+ raisewindow(focuswin->id);
+
+ if (!getpointer(focuswin->id, &pointx, &pointy))
+ {
+ return;
+ }
+
+ focuswin->width = focuswin->width + focuswin->x - mon_x;
+ focuswin->height = focuswin->height + focuswin->y - mon_y;
+
+ focuswin->x = mon_x;
+ focuswin->y = mon_y;
+ moveresize(focuswin->id, focuswin->x, focuswin->y, focuswin->width, focuswin->height);
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0, 0,
+ pointx, pointy);
+ xcb_flush(conn);
+};
+
+void growtopright(void)
+{
+ int16_t pointx;
+ int16_t pointy;
+ int16_t mon_x;
+ int16_t mon_y;
+ uint16_t mon_width;
+
+ if (NULL == focuswin)
+ {
+ return;
+ }
+
+ if (NULL == focuswin->monitor)
+ {
+ mon_width = screen->width_in_pixels;
+ mon_x = 0;
+ mon_y = 0;
+ }
+ else
+ {
+ mon_width = focuswin->monitor->width;
+ mon_x = focuswin->monitor->x;
+ mon_y = focuswin->monitor->y;
+ }
+
+ raisewindow(focuswin->id);
+
+ if (!getpointer(focuswin->id, &pointx, &pointy))
+ {
+ return;
+ }
+
+ focuswin->width = mon_x + mon_width - focuswin->x - (conf.borderwidth * 2);
+ focuswin->height = focuswin->height + focuswin->y - mon_y;
+
+ focuswin->y = mon_y;
+
+ moveresize(focuswin->id, focuswin->x, focuswin->y, focuswin->width, focuswin->height);
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0, 0,
+ pointx, pointy);
+ xcb_flush(conn);
+}
+
+void growbotleft(void)
+{
+ int16_t pointx;
+ int16_t pointy;
+ int16_t mon_x;
+ int16_t mon_y;
+ uint16_t mon_height;
+
+ if (NULL == focuswin)
+ {
+ return;
+ }
+
+ if (NULL == focuswin->monitor)
+ {
+ mon_x = 0;
+ mon_y = 0;
+ mon_height = screen->height_in_pixels;
+ }
+ else
+ {
+ mon_x = focuswin->monitor->x;
+ mon_y = focuswin->monitor->y;
+ mon_height = focuswin->monitor->height;
+ }
+
+ raisewindow(focuswin->id);
+
+ if (!getpointer(focuswin->id, &pointx, &pointy))
+ {
+ return;
+ }
+
+ focuswin->width = focuswin->width + focuswin->x - mon_x;
+ focuswin->height = mon_y + mon_height - focuswin->y - (conf.borderwidth * 2);
+
+ focuswin->x = mon_x;
+
+ moveresize(focuswin->id, focuswin->x, focuswin->y, focuswin->width, focuswin->height);
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0, 0,
+ pointx, pointy);
+ xcb_flush(conn);
+}
+
+void growbotright(void)
+{
+ int16_t pointx;
+ int16_t pointy;
+ int16_t mon_x;
+ int16_t mon_y;
+ uint16_t mon_width;
+ uint16_t mon_height;
+
+ if (NULL == focuswin)
+ {
+ return;
+ }
+
+ if (NULL == focuswin->monitor)
+ {
+ mon_width = screen->width_in_pixels;
+ mon_height = screen->height_in_pixels;
+ mon_x = 0;
+ mon_y = 0;
+ }
+ else
+ {
+ mon_width = focuswin->monitor->width;
+ mon_height = focuswin->monitor->height;
+ mon_x = focuswin->monitor->x;
+ mon_y = focuswin->monitor->y;
+ }
+
+ raisewindow(focuswin->id);
+
+ if (!getpointer(focuswin->id, &pointx, &pointy))
+ {
+ return;
+ }
+
+ focuswin->width = mon_x + mon_width - focuswin->x - (conf.borderwidth * 2);
+ focuswin->height = mon_y + mon_height - focuswin->y - (conf.borderwidth * 2);
+
+ moveresize(focuswin->id, focuswin->x, focuswin->y, focuswin->width, focuswin->height);
+ xcb_warp_pointer(conn, XCB_NONE, focuswin->id, 0, 0, 0, 0,
+ pointx, pointy);
+ xcb_flush(conn);
+}
void deletewin(void)
@@ -3007,6 +3184,22 @@ void handle_keypress(xcb_key_press_event_t *ev)
resizestep(focuswin, 'l');
break;
+ case KEY_Y:
+ growtopleft();
+ break;
+
+ case KEY_U:
+ growtopright();
+ break;
+
+ case KEY_B:
+ growbotleft();
+ break;
+
+ case KEY_N:
+ growbotright();
+ break;
+
default:
/* Ignore other shifted keys. */
break;
*****************************************************************************************
*****************************************************************************************
*****************************************************************************************
*****************************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment