Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add EWMH support
  • Loading branch information
ivoarch committed Jun 13, 2014
1 parent 8269f90 commit 639d554
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -74,4 +74,6 @@ ratpoison_SOURCES = actions.c \
window.c \
window.h \
xinerama.c \
xinerama.h
xinerama.h \
ewmh.c \
ewmh.h
122 changes: 122 additions & 0 deletions src/ewmh.c
@@ -0,0 +1,122 @@
/* Copyright (C) 2010 Lincoln de Sousa <lincoln@comum.org>
*
* This file is part of ratpoison.
*
* ratpoison is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* ratpoison is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/

#include <X11/Xlib.h>
#include "ratpoison.h"

void
init_ewmh (void)
{
Window net_swc, root;
unsigned long data[1];

root = DefaultRootWindow (dpy);

/* Here we create a very simple window, it should not have any better
* setup since it'll never be shown. */
net_swc = XCreateSimpleWindow (dpy, root, 0, 0, 1, 1, 0, 0, 0);

/* Now it's time to setup EWMH properties _NET_WM_NAME and
* _NET_SUPPORTING_WM_CHECK (both in offscreen window and in root) */
XChangeProperty (dpy, net_swc, _net_wm_name, utf8_string,
8, PropModeReplace, (unsigned char *) "Ratpoison", 9);

data[0] = net_swc;
XChangeProperty (dpy, net_swc, _net_supporting_wm_check,
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) data, 1);

XChangeProperty (dpy, root,
XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK", False),
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) data, 1);
}

void
ewmh_set_number_of_desktops (void)
{

unsigned long data[1];

data[0] = list_size (&rp_groups);
XChangeProperty (dpy, DefaultRootWindow (dpy),
XInternAtom (dpy, "_NET_NUMBER_OF_DESKTOPS", False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) data, 1);

}

void
ewmh_set_current_desktop (int group)
{

unsigned long data[1];

data[0] = group;
XChangeProperty (dpy, DefaultRootWindow (dpy),
XInternAtom (dpy, "_NET_CURRENT_DESKTOP", False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) data, 1);
}

void
ewmh_set_client_list ()
{

rp_window_elem *we;
int count, i, j;
Window *windows, *stacked_windows;

count = list_size (&rp_current_group->mapped_windows);
windows = xmalloc (sizeof (Window) * count);
stacked_windows = xmalloc (sizeof (Window) * count);
i = 0;

list_for_each_entry (we, &rp_current_group->mapped_windows, node)
windows[i++] = we->win->w;
for (i = 0, j = count-1; j >= 0; j--, i++)
stacked_windows[j] = windows[i];

XChangeProperty (dpy, DefaultRootWindow (dpy),
XInternAtom (dpy, "_NET_CLIENT_LIST", False),
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) windows, count);

XChangeProperty (dpy, DefaultRootWindow (dpy),
XInternAtom (dpy, "_NET_CLIENT_LIST_STACKING", False),
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) stacked_windows, count);

free (windows);
free (stacked_windows);

}

void
ewmh_set_wm_desktop (rp_window *window)
{
unsigned long data[1];

data[0] = rp_current_group->number;
XChangeProperty (dpy, window->w,
XInternAtom (dpy, "_NET_WM_DESKTOP", False),
XA_CARDINAL, 32, PropModeReplace,
(unsigned char *) data, 1);
}
30 changes: 30 additions & 0 deletions src/ewmh.h
@@ -0,0 +1,30 @@
/* Copyright (C) p2010 Lincoln de Sousa <lincoln@comum.org>
*
* This file is part of ratpoison.
*
* ratpoison is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* ratpoison is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/

#ifndef EWMH_H
#define EWMH_H

void init_ewmh (void);
void ewmh_set_number_of_desktops (void);
void ewmh_set_current_desktop (int group);
void ewmh_set_client_list (void);
void ewmh_set_wm_desktop (rp_window *window);

#endif
6 changes: 5 additions & 1 deletion src/globals.c
Expand Up @@ -55,9 +55,12 @@ Atom xa_utf8_string;
/* netwm atoms */
Atom _net_wm_pid;
Atom _net_supported;
Atom _net_active_window;
Atom _net_wm_window_type;
Atom _net_wm_window_type_dialog;
Atom _net_wm_name;
Atom _net_supporting_wm_check;
Atom utf8_string;

int rp_current_screen;
rp_screen *screens;
Expand Down Expand Up @@ -255,6 +258,8 @@ set_rp_window_focus (rp_window *win)
PRINT_DEBUG (("Giving focus to '%s'\n", window_name (win)));
XSetInputFocus (dpy, win->w,
RevertToPointerRoot, CurrentTime);
XChangeProperty(dpy, win->scr->root, _net_active_window, XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&win->w, 1);
}

void
Expand Down Expand Up @@ -335,4 +340,3 @@ rp_text_width (rp_screen *s, char *string, int count)
return XmbTextEscapement (defaults.font, string, count);
#endif
}

3 changes: 3 additions & 0 deletions src/globals.h
Expand Up @@ -132,9 +132,12 @@ extern Atom xa_utf8_string;
/* netwm atoms. */
extern Atom _net_wm_pid;
extern Atom _net_supported;
extern Atom _net_active_window;
extern Atom _net_wm_window_type;
extern Atom _net_wm_window_type_dialog;
extern Atom _net_supporting_wm_check;
extern Atom _net_wm_name;
extern Atom utf8_string;

/* mouse properties */
extern int rat_x;
Expand Down
10 changes: 10 additions & 0 deletions src/group.c
Expand Up @@ -31,6 +31,10 @@ set_current_group_1 (rp_group *g)
rp_current_group = g;
if (g)
g->last_access = counter++;

ewmh_set_number_of_desktops ();
ewmh_set_current_desktop (g->number);
ewmh_set_client_list ();
}

void
Expand All @@ -46,6 +50,8 @@ init_groups(void)
g = group_new (numset_request (group_numset), DEFAULT_GROUP_NAME);
set_current_group_1 (g);
list_add_tail (&g->node, &rp_groups);

ewmh_set_number_of_desktops ();
}

void
Expand Down Expand Up @@ -346,6 +352,8 @@ group_insert_window (struct list_head *h, rp_window_elem *w)
}

list_add_tail(&w->node, h);
ewmh_set_wm_desktop (w->win);
ewmh_set_client_list ();
}

static int
Expand Down Expand Up @@ -480,6 +488,7 @@ groups_del_window (rp_window *win)
{
group_del_window (cur, win);
}
ewmh_set_client_list ();
}

rp_window *
Expand Down Expand Up @@ -661,6 +670,7 @@ group_delete_group (rp_group *g)

list_del (&(g->node));
group_free (g);
ewmh_set_number_of_desktops ();
return GROUP_DELETE_GROUP_OK;
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Expand Up @@ -734,9 +734,12 @@ main (int argc, char *argv[])
PRINT_DEBUG (("_NET_WM_PID = %ld\n", _net_wm_pid));
_net_supported = XInternAtom(dpy, "_NET_SUPPORTED", False);
PRINT_DEBUG (("_NET_SUPPORTED = %ld\n", _net_supported));
_net_active_window = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
_net_wm_window_type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
_net_wm_window_type_dialog = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
_net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", False);
_net_supporting_wm_check = XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK", False);
utf8_string = XInternAtom(dpy, "UTF8_STRING", False);

/* Setup signal handlers. */
XSetErrorHandler(handler);
Expand All @@ -756,6 +759,7 @@ main (int argc, char *argv[])
init_window_stuff ();
init_xinerama ();
init_screens (screen_arg, screen_num);
init_ewmh ();

init_frame_lists ();
update_modifier_map ();
Expand Down
1 change: 1 addition & 0 deletions src/ratpoison.h
Expand Up @@ -80,6 +80,7 @@ extern XGCValues gv;
#include "hook.h"
#include "xinerama.h"
#include "format.h"
#include "ewmh.h"

void clean_up (void);
rp_screen *find_screen (Window w);
Expand Down

0 comments on commit 639d554

Please sign in to comment.