#include <util.h>
#include <X11/cursorfont.h>
#include <X11/extensions/Xrandr.h>
-#include <xcb/xcb.h>
+#include <X11/Xft/Xft.h>
+#include <X11/Xlib-xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_aux.h>
#include <xcb/xcb_event.h>
int xrandr_support;
int xrandr_eventbase;
unsigned int numlockmask = 0;
+
+Display *display;
xcb_connection_t *conn;
xcb_key_symbols_t *syms;
int verbose_layout = 0;
time_t time_started;
pid_t bar_pid;
-#if 0
-XFontSet bar_fs;
-XFontSetExtents *bar_fs_extents;
-#endif
+XftFont *bar_font;
char *bar_fonts;
+XftColor bar_font_color;
struct passwd *pwd;
/* layout manager data */
};
/* function prototypes */
+xcb_char2b_t *char2b(const char *);
int conf_load(char *, int);
void constrain_window(struct ws_win *, struct swm_region *, int);
void do_sync(void);
void store_float_geom(struct ws_win *, struct swm_region *);
void unmanage_window(struct ws_win *);
void update_window(struct ws_win *);
+#ifdef SWM_DEBUG
+char *get_atom_name(xcb_atom_t);
+#endif
/* function definitions */
+xcb_char2b_t *
+char2b(const char *str)
+{
+ xcb_char2b_t *s;
+ size_t i, len;
+
+ len = strlen(str);
+ s = malloc(len * sizeof(xcb_char2b_t));
+ if (!s)
+ return (NULL);
+
+ for (i = 0; i < len; i++) {
+ s[i].byte1 = '\0';
+ s[i].byte2 = str[i];
+ }
+
+ return (s);
+}
+
int
parse_rgb(const char *rgb, uint16_t *rr, uint16_t *gg, uint16_t *bb)
{
if (win == NULL)
return;
+ DNPRINTF(SWM_D_PROP, "ewmh_update_win_state: window: 0x%x, state: %ld, "
+ "action: %ld\n", win->id, state, action);
+
if (state == ewmh[_NET_WM_STATE_FULLSCREEN].atom)
mask = EWMH_F_FULLSCREEN;
if (state == ewmh[_NET_WM_STATE_ABOVE].atom)
void
bar_print(struct swm_region *r, const char *s)
{
- size_t len;
- xcb_rectangle_t rect;
- uint32_t gcv[1];
+ size_t len;
+ xcb_rectangle_t rect;
+ uint32_t gcv[1];
+ int32_t x;
+ XGlyphInfo info;
+ XftDraw *draw;
len = strlen(s);
- /* FIXME fix bar font position calculations */
-#if 0
- int x = 0;
- XRectangle ibox, lbox;
- XmbTextExtents(bar_fs, s, len, &ibox, &lbox);
+
+ XftTextExtentsUtf8(display, bar_font, (FcChar8 *)s, len, &info);
switch (bar_justify) {
case SWM_BAR_JUSTIFY_LEFT:
x = SWM_BAR_OFFSET;
break;
case SWM_BAR_JUSTIFY_CENTER:
- x = (WIDTH(r) - lbox.width) / 2;
+ x = (WIDTH(r) - info.width) / 2;
break;
case SWM_BAR_JUSTIFY_RIGHT:
- x = WIDTH(r) - lbox.width - SWM_BAR_OFFSET;
+ x = WIDTH(r) - info.width - SWM_BAR_OFFSET;
break;
}
if (x < SWM_BAR_OFFSET)
x = SWM_BAR_OFFSET;
-#endif
rect.x = 0;
rect.y = 0;
xcb_change_gc(conn, r->s->bar_gc, XCB_GC_BACKGROUND, gcv);
gcv[0] = r->s->c[SWM_S_COLOR_BAR_FONT].color;
xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv);
-#if 0
- xcb_image_text_8(conn, len, r->bar->buffer, r->s->bar_gc, x,
- (bar_fs_extents->max_logical_extent.height - lbox.height) / 2 -
- lbox.y, s);
-#else
- /* workaround */
- xcb_image_text_8(conn, len, r->bar->buffer, r->s->bar_gc, 4, 14, s);
-#endif
+
+ draw = XftDrawCreate(display, r->bar->buffer,
+ DefaultVisual(display, r->s->idx),
+ DefaultColormap(display, r->s->idx));
+
+ XftDrawStringUtf8(draw, &bar_font_color, bar_font, x, bar_font->height,
+ (FcChar8 *)s, len);
+
+ XftDrawDestroy(draw);
/* blt */
xcb_copy_area(conn, r->bar->buffer, r->bar->id, r->s->bar_gc, 0, 0,
void
bar_setup(struct swm_region *r)
{
- char *default_string;
- char **missing_charsets;
- int num_missing_charsets = 0;
- int i;
+ char *font;
xcb_screen_t *screen = get_screen(r->s->idx);
uint32_t wa[3];
+ XRenderColor color;
-#if 0
- if (bar_fs) {
- XFreeFontSet(display, bar_fs);
- bar_fs = NULL;
+ if (bar_font) {
+ XftColorFree(display, DefaultVisual(display, r->s->idx),
+ DefaultColormap(display, r->s->idx), &bar_font_color);
+ XftFontClose(display, bar_font);
+ bar_font = NULL;
}
-#endif
if ((r->bar = calloc(1, sizeof(struct swm_bar))) == NULL)
err(1, "bar_setup: calloc: failed to allocate memory.");
-#if 0
- 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);
+ while ((font = strsep(&bar_fonts, " ,")) != NULL) {
+ if (*font == '\0')
+ continue;
- 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.");
+ DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", font);
+ bar_font = XftFontOpenName(display, r->s->idx, font);
+ if (!bar_font) {
+ warnx("unable to load font %s", font);
+ continue;
+ } else {
+ DNPRINTF(SWM_D_INIT, "successfully opened font %s\n",
+ font);
+ break;
+ }
}
+ if (bar_font == NULL)
+ errx(1, "unable to open a font");
- if (bar_fs == NULL)
- errx(1, "Error creating font set structure.");
-
- bar_fs_extents = XExtentsOfFontSet(bar_fs);
-
- bar_height = bar_fs_extents->max_logical_extent.height +
- 2 * bar_border_width;
+ bar_height = bar_font->height + 4 * bar_border_width;
if (bar_height < 1)
bar_height = 1;
-#else
- /* workaround */
- bar_height = 24;
-#endif
+
+ color.alpha = 0xffff;
+ color.red = (r->s->c[SWM_S_COLOR_BAR_FONT].color >> 16) & 0xffff;
+ color.green = (r->s->c[SWM_S_COLOR_BAR_FONT].color >> 8) & 0xffff;
+ color.blue = r->s->c[SWM_S_COLOR_BAR_FONT].color & 0xffff;
+ if (!XftColorAllocValue(display, DefaultVisual(display, r->s->idx),
+ DefaultColormap(display, r->s->idx), &color, &bar_font_color))
+ warn("unable to allocate Xft color");
+
X(r->bar) = X(r);
Y(r->bar) = bar_at_bottom ? (Y(r) + HEIGHT(r) - bar_height) : Y(r);
WIDTH(r->bar) = WIDTH(r) - 2 * bar_border_width;
ce.y, ce.width, ce.height, ce.border_width);
xcb_send_event(conn, False, win->id, XCB_EVENT_MASK_STRUCTURE_NOTIFY,
- (char *)&ce);
+ (char *)&ce);
}
int
void
unmap_window(struct ws_win *win)
{
+ DNPRINTF(SWM_D_EVENT, "unmap_window: window: 0x%x\n", win->id);
+
if (win == NULL)
return;
/* don't unmap again */
- if (getstate(win->id) == XCB_ICCCM_WM_STATE_ICONIC)
+ if (getstate(win->id) == XCB_ICCCM_WM_STATE_WITHDRAWN)
return;
- set_win_state(win, XCB_ICCCM_WM_STATE_ICONIC);
+ set_win_state(win, XCB_ICCCM_WM_STATE_WITHDRAWN);
xcb_unmap_window(conn, win->id);
xcb_change_window_attributes(conn, win->id,
bar_extra = 1;
unmap_all();
+ XftFontClose(display, bar_font);
+ XftColorFree(display, DefaultVisual(display, r->s->idx),
+ DefaultColormap(display, r->s->idx), &bar_font_color);
xcb_key_symbols_free(syms);
xcb_flush(conn);
xcb_disconnect(conn);
if ((cfw = find_window(cur_focus)) != NULL)
unfocus_win(cfw);
else {
+#if 0
/* use larger hammer since the window was killed somehow */
- /* TAILQ_FOREACH(cfw, &win->ws->winlist, entry)
+ TAILQ_FOREACH(cfw, &win->ws->winlist, entry)
if (cfw->ws && cfw->ws->r && cfw->ws->r->s)
xcb_change_window_attributes(conn, cfw->id,
XCB_CW_BORDER_PIXEL,
- &cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);*/
+ &cfw->ws->r->s->c[SWM_S_COLOR_UNFOCUS].color);
+#endif
}
win->ws->focus = win;
win->id, XCB_CURRENT_TIME);
grabbuttons(win, 1);
xcb_change_window_attributes(conn, win->id,
- XCB_CW_BORDER_PIXEL,
- &win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
+ XCB_CW_BORDER_PIXEL,
+ &win->ws->r->s->c[SWM_S_COLOR_FOCUS].color);
if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS ||
win->ws->always_raise)
map_window_raised(win->id);
event_drain(XCB_ENTER_NOTIFY);
else
xcb_flush(conn);
+
+ DNPRINTF(SWM_D_WS, "switchws: done\n");
}
void
char s[8];
FILE *lfile;
size_t len;
- XRectangle ibox, lbox;
+ XGlyphInfo info;
DNPRINTF(SWM_D_MISC, "search_win\n");
snprintf(s, sizeof s, "%d", i);
len = strlen(s);
- /* FIXME fix calculations */
-#if 0
- XmbTextExtents(bar_fs, s, len, &ibox, &lbox);
-#endif
+ XftTextExtentsUtf8(display, bar_font, (FcChar8 *)s, len, &info);
w = xcb_generate_id(conn);
wa[0] = r->s->c[SWM_S_COLOR_FOCUS].color;
wa[1] = r->s->c[SWM_S_COLOR_UNFOCUS].color;
-#if 0
xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, win->id, 0, 0,
- lbox.width + 4, bar_fs_extents->max_logical_extent.height,
+ info.width + 4, bar_font->height + 4,
1, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT,
XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa);
-#else
- /* workaround */
- xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, win->id, 0, 0,
- 22, 20, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT,
- XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL |
- XCB_CW_BORDER_PIXEL, wa);
-#endif
sw->indicator = w;
TAILQ_INSERT_TAIL(&search_wl, sw, entry);
XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, gcv);
map_window_raised(w);
-#if 0
- xcb_image_text_8(conn, len, w, sw->gc, 2,
- (bar_fs_extents->max_logical_extent.height -
- lbox.height) / 2 - lbox.y, s);
-#else
- /* workaround */
- xcb_image_text_8(conn, len, w, sw->gc, 6, 14, s);
-#endif
+ xcb_image_text_8(conn, len, w, sw->gc, 2, bar_font->height, s);
DNPRINTF(SWM_D_MISC, "search_win: mapped window: 0x%x\n", w);
uint32_t wc[5];
mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
- XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
- XCB_CONFIG_WINDOW_BORDER_WIDTH;
+ XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
+ XCB_CONFIG_WINDOW_BORDER_WIDTH;
wc[0] = X(win);
wc[1] = Y(win);
wc[2] = WIDTH(win);
kc = modmap[i * modmap_r->keycodes_per_modifier
+ j];
- if (kc == *((xcb_keycode_t *)xcb_key_symbols_get_keycode(syms,
+ if (kc == *((xcb_keycode_t *)xcb_key_symbols_get_keycode(syms,
XK_Num_Lock)))
numlockmask = (1 << i);
}
if (asprintf(&bar_fonts, "%s,%s", value, bar_fonts) == -1)
err(1, "setconfvalue: asprintf: failed to allocate "
"memory for bar_fonts.");
-
free(b);
break;
case SWM_S_BAR_FORMAT:
{
xcb_get_geometry_reply_t *wa;
-
wa = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, w), NULL);
DNPRINTF(SWM_D_MISC, "print_win_geom: window: 0x%x, root: 0x%x, "
}
}
-/*void
+#if 0
+void
visibilitynotify(xcb_visibility_notify_event_t *e)
{
DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: 0x%x\n",
e->window);
-}*/
+}
+#endif
void
clientmessage(xcb_client_message_event_t *e)
enable_wm(void)
{
int num_screens, i;
- const uint32_t val = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
+ const uint32_t val = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
xcb_screen_t *sc;
xcb_void_cookie_t wac;
xcb_generic_error_t *error;
DNPRINTF(SWM_D_INIT, "enable_wm: screen %d, root: 0x%x\n",
i, sc->root);
wac = xcb_change_window_attributes_checked(conn, sc->root,
- XCB_CW_EVENT_MASK, &val);
+ XCB_CW_EVENT_MASK, &val);
if ((error = xcb_request_check(conn, wac))) {
DNPRINTF(SWM_D_INIT, "enable_wm: error_code: %u\n",
error->error_code);
cursor = xcb_generate_id(conn);
xcb_create_glyph_cursor(conn, cursor, cursor_font, cursor_font,
- XC_left_ptr, XC_left_ptr + 1, 0, 0, 0, 0xffff, 0xffff, 0xffff);
+ XC_left_ptr, XC_left_ptr + 1, 0, 0, 0, 0xffff, 0xffff, 0xffff);
wa[0] = cursor;
/* map physical screens */
start_argv = argv;
warnx("Welcome to spectrwm V%s Build: %s", SPECTRWM_VERSION, buildstr);
- if (!setlocale(LC_CTYPE, "") || !setlocale(LC_TIME, ""))
+ if (!setlocale(LC_CTYPE, "") || !setlocale(LC_TIME, ""))
warnx("no locale support");
/* handle some signals */
sact.sa_flags = SA_NOCLDSTOP;
sigaction(SIGCHLD, &sact, NULL);
- conn = xcb_connect(NULL, NULL);
+ if (!(display = XOpenDisplay(0)))
+ errx(1, "can not open display");
+
+ conn = XGetXCBConnection(display);
if (xcb_connection_has_error(conn))
errx(1, "can not get XCB connection");
+ XSetEventQueueOwner(display, XCBOwnsEventQueue);
+
xcb_prefetch_extension_data(conn, &xcb_randr_id);
xfd = xcb_get_file_descriptor(conn);
for (i = 0; i < num_screens; ++i)
if (screens[i].bar_gc != 0)
xcb_free_gc(conn, screens[i].bar_gc);
-#if 0
- XFreeFontSet(display, bar_fs);
-#endif
+
+ XftFontClose(display, bar_font);
+ XftColorFree(display, DefaultVisual(display, 0),
+ DefaultColormap(display, 0), &bar_font_color);
xcb_key_symbols_free(syms);
xcb_flush(conn);
xcb_disconnect(conn);