From 55ed26799b4e8afd154dd07565312325dc6ba7a6 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 4 Jun 2007 21:39:59 +0000 Subject: [PATCH] throw away !obrender --- configure | 24 --- rspanel.c | 468 ++---------------------------------------------------- 2 files changed, 17 insertions(+), 475 deletions(-) diff --git a/configure b/configure index c01d554..606c071 100755 --- a/configure +++ b/configure @@ -27,28 +27,6 @@ else echo no fi -echo -n "checking for libXft " -xft=no -if pkg-config --exists xft; then - echo yes - CFLAGS="$CFLAGS -DXFT" - FOUND="$FOUND xft" - xft=yes -else - echo no -fi - -echo -n "checking for Pango..." -pango=no -if pkg-config --exists pango pangoxft; then - echo yes - CFLAGS="$CFLAGS -DPANGO" - FOUND="$FOUND pango pangoxft" - pango=yes -else - echo no -fi - echo -n "checking for ObRender..." obrender=no if pkg-config --atleast-version 3.3.995 obrender-3.0; then @@ -95,8 +73,6 @@ echo \ install $\(PROGNAME\) /usr/local/bin >> Makefile echo done echo echo ObRender ................ : $obrender -echo Pango ................... : $pango -echo AntiAliased XFT text .... : $xft echo LibXpm default icon ..... : $xpm echo echo All done. Now type: make diff --git a/rspanel.c b/rspanel.c index 0510b73..93c36bb 100644 --- a/rspanel.c +++ b/rspanel.c @@ -33,45 +33,19 @@ #else int WINWIDTH = 827; #endif -#define FONT_NAME "-*-Technical*-m*-r-*-*-14-*-*" -#define XFT_FONT "Arial Unicode MS-12" -#define PANGO_FONT_PREF "Utopia" -//#define PANGO_FONT_PREF "Technical" -#define PANGO_FONT_SIZE 13 -//#define PAGER /* use a desktop pager? */ -#define PAGER_DIGIT_WIDTH 6 -#define PAGER_BUTTON_WIDTH 20 -#ifdef PAGER -#undef PANGO -#endif /* don't edit these */ #define TEXTPAD 6 #define GRILL_WIDTH 10 -#ifdef PANGO -#undef XFT -#define XFT -#include -#include -#endif -#ifdef XFT -#include -#endif - -#ifdef OBRENDER -#warning wtf #include #include -#endif #include "rspanel.h" Window rspanelwin; Display *dd; Window root_win; -Pixmap generic_icon; -Pixmap generic_mask; GC fore_gc; taskbar tb; int scr_screen; @@ -81,7 +55,6 @@ int scr_height; int text_y; int pager_size; -#ifdef OBRENDER RrInstance *inst; RrAppearance *background; RrAppearance *focused_task; @@ -94,33 +67,6 @@ RrAppearance *focused_text; /* we draw stuff to this guy then set him as a window * background pixmap, yay no flickering! */ Pixmap bgpixmap; -#endif - -#ifdef XFT -XftDraw *xftdraw; -#ifdef PANGO -PangoLayout *pl; -#else -XftFont *xfs; -#endif -#else -XFontStruct *xfs; -#endif - -struct colors { - unsigned short red, green, blue; -} cols[] = { - {0xd75c, 0xd75c, 0xe75c}, /* 0. light gray */ - {0xbefb, 0xbaea, 0xcefb}, /* 1. mid gray */ - {0xaefb, 0xaaea, 0xfefb}, /* 2. dark gray */ - {0xefbe, 0xefbe, 0xffbe}, /* 3. white */ - {0x8617, 0x8207, 0x9617}, /* 4. darkest gray */ - {0x0000, 0x0000, 0x1000}, /* 5. black */ -}; - -#define PALETTE_COUNT (sizeof (cols) / sizeof (cols[0].red) / 3) - -unsigned long palette[PALETTE_COUNT]; char *atom_names[] = { /* clients */ @@ -203,111 +149,6 @@ static void *get_prop_data(Window win, Atom prop, Atom type, int *items) return prop_data; } -static void set_foreground(int index) -{ - XSetForeground(dd, fore_gc, palette[index]); -} - -static void draw_line(int x, int y, int a, int b) -{ - XDrawLine(dd, tb.win, fore_gc, x, y, a, b); -} - -static void fill_rect(int x, int y, int a, int b) -{ - XFillRectangle(dd, tb.win, fore_gc, x, y, a, b); -} - -static void scale_icon(task * tk) -{ - int xx, yy, x, y; - unsigned int w, h, d, bw; - Pixmap pix, mk = None; - XGCValues gcv; - GC mgc = mgc; - - XGetGeometry(dd, tk->icon, &pix, &x, &y, &w, &h, &bw, &d); - pix = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, scr_depth); - - if (tk->mask != None) { - mk = XCreatePixmap(dd, tk->win, ICONWIDTH, ICONHEIGHT, 1); - gcv.subwindow_mode = IncludeInferiors; - gcv.graphics_exposures = False; - mgc = XCreateGC(dd, mk, GCGraphicsExposures | GCSubwindowMode, &gcv); - } - - set_foreground(3); - - /* this is my simple & dirty scaling routine */ - for (y = ICONHEIGHT - 1; y >= 0; y--) { - yy = (y * h) / ICONHEIGHT; - for (x = ICONWIDTH - 1; x >= 0; x--) { - xx = (x * w) / ICONWIDTH; - if (d != scr_depth) - XCopyPlane(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y, 1); - else - XCopyArea(dd, tk->icon, pix, fore_gc, xx, yy, 1, 1, x, y); - if (mk != None) - XCopyArea(dd, tk->mask, mk, mgc, xx, yy, 1, 1, x, y); - } - } - - if (mk != None) { - XFreeGC(dd, mgc); - tk->mask = mk; - } - - tk->icon = pix; -} - -static void get_task_hinticon(task * tk) -{ - XWMHints *hin; - - if (tk->icon != None && tk->icon != generic_icon) - if (tk->icon_copied) { - XFreePixmap(dd, tk->icon); - if (tk->mask != None && tk->mask != generic_mask) - XFreePixmap(dd, tk->mask); - } - - tk->icon = None; - tk->mask = None; - - hin = (XWMHints *)get_prop_data(tk->win, XA_WM_HINTS, XA_WM_HINTS, 0); - if (hin) { - if ((hin->flags & IconPixmapHint)) { - if ((hin->flags & IconMaskHint)) { - tk->mask = hin->icon_mask; - } - - tk->icon = hin->icon_pixmap; - tk->icon_copied = 1; - scale_icon(tk); - } - XFree(hin); - } - - if (tk->icon == None) { - tk->icon = generic_icon; - if (tk->mask != None) - XFreePixmap(dd, tk->mask); - tk->mask = generic_mask; - } -} - -static void get_task_kdeicon(task * tk) -{ - unsigned long *data; - - data = get_prop_data(tk->win, atoms[KWM_WIN_ICON], atoms[KWM_WIN_ICON], 0); - if (data) { - tk->icon = data[0]; - tk->mask = data[1]; - XFree(data); - } -} - static int generic_get_int(Window win, Atom at) { int num = 0; @@ -364,10 +205,12 @@ static int get_current_desktop(void) return generic_get_int(root_win, atoms[_NET_CURRENT_DESKTOP]); } +#ifdef PAGER static int get_number_of_desktops(void) { return generic_get_int(root_win, atoms[_NET_NUMBER_OF_DESKTOPS]); } +#endif static void add_task(Window win, int focus) { @@ -392,12 +235,7 @@ static void add_task(Window win, int focus) tk->iconified = is_iconified(win); tk->shaded = is_shaded(win); - get_task_kdeicon(tk); - if (tk->icon == None) - get_task_hinticon(tk); - - XSelectInput(dd, win, PropertyChangeMask | FocusChangeMask - | StructureNotifyMask); + XSelectInput(dd, win, PropertyChangeMask | StructureNotifyMask); /* now append it to our linked list */ tb.num_tasks++; @@ -425,14 +263,11 @@ static void set_prop(Window win, Atom at, Atom type, long val) static Window gui_create_taskbar(void) { Window win; - MWMHints mwm; XSizeHints size_hints; - XWMHints wmhints; XSetWindowAttributes att; XClassHint xclhints; - att.background_pixel = palette[0]; - att.event_mask = ButtonPressMask | ExposureMask; + att.event_mask = ButtonPressMask; win = rspanelwin = XCreateWindow(/* display */ dd, /* parent */ root_win, @@ -445,7 +280,7 @@ static Window gui_create_taskbar(void) /* depth */ CopyFromParent, /* class */ InputOutput, /* visual */ CopyFromParent, - /*value mask*/ CWBackPixel | CWEventMask, + /*value mask*/ CWEventMask, /* attribs */ &att); /* reside on ALL desktops */ @@ -453,20 +288,9 @@ static Window gui_create_taskbar(void) set_prop(win, atoms[_NET_WM_WINDOW_TYPE], XA_ATOM, atoms[_NET_WM_WINDOW_TYPE_DOCK]); set_prop(win, atoms[_NET_WM_STATE], XA_ATOM, atoms[_NET_WM_STATE_BELOW]); - /* use old gnome hint since sawfish doesn't support _NET_WM_STRUT */ - set_prop(win, atoms[_WIN_HINTS], XA_CARDINAL, - WIN_HINTS_SKIP_FOCUS | WIN_HINTS_SKIP_WINLIST | - WIN_HINTS_SKIP_TASKBAR | WIN_HINTS_DO_NOT_COVER); XChangeProperty(dd, win, XA_WM_NAME, XA_STRING, 8, PropModeReplace, (unsigned char *)"rspanel", 7); - /* borderless motif hint */ - bzero(&mwm, sizeof(mwm)); - mwm.flags = MWM_HINTS_DECORATIONS; - XChangeProperty(dd, win, atoms[_MOTIF_WM_HINTS], atoms[_MOTIF_WM_HINTS], 32, - PropModeReplace, (unsigned char *)&mwm, - sizeof(MWMHints) / 4); - /* make sure the WM obays our window position */ size_hints.flags = PPosition; /*XSetWMNormalHints (dd, win, &size_hints); */ @@ -474,99 +298,23 @@ static Window gui_create_taskbar(void) PropModeReplace, (unsigned char *)&size_hints, sizeof(XSizeHints) / 4); - /* make our window unfocusable */ - wmhints.flags = InputHint; - wmhints.input = False; - /*XSetWMHints (dd, win, &wmhints); */ - XChangeProperty(dd, win, XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace, - (unsigned char *)&wmhints, sizeof(XWMHints) / 4); - xclhints.res_name = "rspanel"; xclhints.res_class = "RSPanel"; XSetClassHint(dd, win, &xclhints); XMapWindow(dd, win); -#ifdef XFT - xftdraw = XftDrawCreate(dd, win, DefaultVisual(dd, scr_screen), - DefaultColormap(dd, scr_screen)); -#endif -#ifdef PANGO - g_type_init(); -#endif - return win; } static void gui_init(void) { XGCValues gcv; - XColor xcl; - unsigned int i; -#ifndef XFT - char *fontname; -#endif -#ifdef PANGO - PangoContext *context; - PangoFontDescription *pfd; -#endif - - i = 0; - do { - xcl.red = cols[i].red; - xcl.green = cols[i].green; - xcl.blue = cols[i].blue; - XAllocColor(dd, DefaultColormap(dd, scr_screen), &xcl); - palette[i] = xcl.pixel; - i++; - } while (i < PALETTE_COUNT); - -#ifdef PANGO -#elif XFT - xfs = XftFontOpenName(dd, scr_screen, XFT_FONT); -#else - fontname = FONT_NAME; - do { - xfs = XLoadQueryFont(dd, fontname); - fontname = "fixed"; - } while (!xfs); -#endif gcv.graphics_exposures = False; -#ifndef PANGO -# ifdef XFT - text_y = xfs->ascent + ((WINHEIGHT - (xfs->ascent + xfs->descent)) / 2); - fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv); -# else - text_y = xfs->ascent + ((WINHEIGHT - xfs->ascent) / 2); - gcv.font = xfs->fid; - fore_gc = XCreateGC(dd, root_win, GCFont | GCGraphicsExposures, &gcv); -# endif -#else - pfd = pango_font_description_new(); - pango_font_description_set_absolute_size(pfd, PANGO_FONT_SIZE*PANGO_SCALE); - pango_font_description_set_family(pfd, PANGO_FONT_PREF); - context = pango_xft_get_context(dd, root_win); - pango_context_set_font_description(context, pfd); - pl = pango_layout_new(context); - - pango_layout_set_single_paragraph_mode(pl, TRUE); - pango_layout_set_ellipsize(pl, PANGO_ELLIPSIZE_END); - - text_y = (WINHEIGHT*PANGO_SCALE-7*PANGO_SCALE); - pango_font_description_free(pfd); - g_object_unref(context); fore_gc = XCreateGC(dd, root_win, GCGraphicsExposures, &gcv); -#endif -#ifdef HAVE_XPM - XpmCreatePixmapFromData(dd, root_win, icon_xpm, &generic_icon, - &generic_mask, NULL); -#else - generic_icon = 0; -#endif -#ifdef OBRENDER inst = RrInstanceNew(dd, scr_screen); background = RrAppearanceNew(inst, 0); focused_task = RrAppearanceNew(inst, 0); @@ -603,32 +351,8 @@ static void gui_init(void) shaded_text->texture[0].data.text.color = RrColorNew(inst, 50, 60, 90); iconified_text->texture[0].data.text.color = RrColorNew(inst, 200, 200, 200); focused_text->texture[0].data.text.color = RrColorNew(inst, 230, 230, 255); -#endif -} - -static void gui_draw_vline(int x) -{ - set_foreground(4); - draw_line(x, 0, x, WINHEIGHT); - set_foreground(3); - draw_line(x + 1, 0, x + 1, WINHEIGHT); -} - -static void draw_box(int x, int width) -{ - set_foreground(1); /* mid gray */ - fill_rect(x + 3, 2, width - 2, WINHEIGHT - 4); - - set_foreground(3); /* white */ - draw_line(x + 3, WINHEIGHT - 2, x + width - 1, WINHEIGHT - 2); - draw_line(x + width - 1, 1, x + width - 1, WINHEIGHT - 2); - - set_foreground(4); /* darkest gray */ - draw_line(x + 3, 1, x + width - 1, 1); - draw_line(x + 3, 2, x + 3, WINHEIGHT - 3); } -#ifdef OBRENDER #define PADDING 4 static void gui_draw_task(task *tk, int redraw) { @@ -663,145 +387,6 @@ static void gui_draw_task(task *tk, int redraw) XClearWindow(dd, tb.win); } } -#else -static void gui_draw_task(task * tk, int redraw) -{ - int x = tk->pos_x; - int taskw = tk->width; -#ifdef XFT -#ifndef PANGO - int len; - XGlyphInfo ext; -#endif - XftColor col; -#endif - (void)redraw; - gui_draw_vline(x); - - if (tk->focused) { - draw_box(x, taskw); - } else { - set_foreground(0); /* mid gray */ - fill_rect(x + 2, 0, taskw - 1, WINHEIGHT); - } - - if (tk->name) { - int text_x = x + TEXTPAD + TEXTPAD + (tk->icon ? ICONWIDTH : -1*ICONWIDTH/4); -#define SETCOL(x) col.color.red = cols[x].red;\ - col.color.green = cols[x].green;\ - col.color.blue = cols[x].blue; -#ifdef PANGO - - pango_layout_set_width(pl, /*-1);*/(taskw - text_x + x) * PANGO_SCALE); - pango_layout_set_text(pl, tk->name, -1); - col.color.alpha = 0xffff; - - if (tk->iconified) { - SETCOL(3) - pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x+2)*PANGO_SCALE, text_y + 2); - SETCOL(4) - } else if (tk->shaded) { - SETCOL(3) - pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), (text_x-2)*PANGO_SCALE, text_y - 2); - SETCOL(4) - } else { - SETCOL(5) - } - pango_xft_render_layout_line(xftdraw, &col, pango_layout_get_line(pl, 0), text_x*PANGO_SCALE, text_y); - -#elif XFT - - /* check how many chars can fit */ - len = strlen(tk->name); - while (1) { - XftTextExtentsUtf8(dd, xfs, tk->name, len, &ext); - if (ext.width < taskw - (text_x - x) - 2 || len <= 0) - break; - len--; - } - - col.color.alpha = 0xffff; - - if (tk->iconified) { - /* draw task's name dark (iconified) */ - SETCOL(3) - XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y + 1, tk->name, - len); - SETCOL(4) - } else if (tk->shaded) { - /* draw task's name dark (shaded) */ - SETCOL(3) - XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y - 1, tk->name, - len); - SETCOL(4) - } else { - SETCOL(5) -#undef SETCOL - } - - /* draw task's name here */ - XftDrawStringUtf8(xftdraw, &col, xfs, text_x, text_y, tk->name, len); -#else - - /* check how many chars can fit */ - len = strlen(tk->name); - - while (XTextWidth(xfs, tk->name, len) >= taskw - (text_x - x) - 2 - && len > 0) - len--; - - if (tk->iconified) { - /* draw task's name dark (iconified) */ - set_foreground(3); - XDrawString(dd, tb.win, fore_gc, text_x, text_y + 1, tk->name, - len); - set_foreground(4); - } else if (tk->shaded) { - /* draw task's name dark (shaded) */ - set_foreground(3); - XDrawString(dd, tb.win, fore_gc, text_x, text_y - 1, tk->name, - len); - set_foreground(4); - } else { - set_foreground(5); - } - - /* draw task's name here */ - XDrawString(dd, tb.win, fore_gc, text_x, text_y, tk->name, len); -#endif - } - -#ifndef HAVE_XPM - if (!tk->icon) - return; -#endif - - /* draw the task's icon */ - XSetClipMask(dd, fore_gc, tk->mask); - XSetClipOrigin(dd, fore_gc, x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2); - XCopyArea(dd, tk->icon, tb.win, fore_gc, 0, 0, ICONWIDTH, ICONHEIGHT, - x + TEXTPAD, (WINHEIGHT - ICONHEIGHT) / 2); - XSetClipMask(dd, fore_gc, None); -} -#endif - -static void draw_dot(int x, int y) -{ - set_foreground(4); - XDrawPoint(dd, tb.win, fore_gc, x, y); - set_foreground(3); - XDrawPoint(dd, tb.win, fore_gc, x + 1, y + 1); -} - -static void draw_grill(int x) -{ - int y = 0; - while (y < WINHEIGHT - 4) { - y += 3; - draw_dot(x + 3, y); - draw_dot(x, y); - } -} static void netwm_action(Window win, atom_t atom, Time time, long l) { @@ -845,7 +430,7 @@ static void switch_desk(int new_desk, Time time) netwm_action(None, _NET_CURRENT_DESKTOP, time, new_desk); } -/* This doesn't work with pango yet */ +/* This doesn't work with obrender yet */ static void pager_draw_button(int x, int num) { char label; @@ -910,14 +495,12 @@ static void gui_draw_taskbar(void) x = pager_size + 2; width = WINWIDTH - (pager_size + GRILL_WIDTH); -#ifdef OBRENDER #warning only rerender if width changed! if (bgpixmap) XFreePixmap(dd, bgpixmap); bgpixmap = XCreatePixmap(dd, root_win, WINWIDTH, WINHEIGHT, RrDepth(inst)); XFreePixmap(dd, RrPaintPixmap(background, WINWIDTH, WINHEIGHT)); XCopyArea(dd, background->pixmap, bgpixmap, fore_gc, 0, 0, WINWIDTH, WINHEIGHT, 0, 0); -#endif if (tb.num_tasks == 0) goto clear; @@ -934,24 +517,9 @@ static void gui_draw_taskbar(void) tk = tk->next; } -#ifdef OBRENDER clear: XSetWindowBackgroundPixmap(dd, tb.win, bgpixmap); XClearWindow(dd, tb.win); -#else - if (x < (width + pager_size + 2)) { -clear: - gui_draw_vline(x); - set_foreground(0); - fill_rect(x + 2, 0, WINWIDTH, WINHEIGHT); - } - - gui_draw_vline(8); - gui_draw_vline(WINWIDTH - 8); - - draw_grill(2); - draw_grill(WINWIDTH - 6); -#endif } static task *find_task(Window win) @@ -1029,8 +597,10 @@ static void taskbar_read_clientlist(void) } win = get_prop_data(root_win, atoms[_NET_ACTIVE_WINDOW], XA_WINDOW, &num); - if (win && num > 0) + if (win && num > 0) { focus_win = win[0]; + XFree(win); + } win = get_prop_data(root_win, atoms[_NET_CLIENT_LIST], XA_WINDOW, &num); if (!win) @@ -1188,7 +758,8 @@ static void handle_propertynotify(Window win, Atom at) task *tk; if (win == root_win) { - /* XXX only redraw the task that got focused/unfocused when _NET_ACTIVE_WINDOW triggers this */ + /* XXX only redraw the task that got focused/unfocused + * when _NET_ACTIVE_WINDOW triggers this */ if (at == atoms[_NET_CLIENT_LIST] || at == atoms[_NET_CURRENT_DESKTOP] || at == atoms[_NET_CLIENT_LIST_STACKING] || at == atoms[_NET_ACTIVE_WINDOW]) { @@ -1209,6 +780,7 @@ static void handle_propertynotify(Window win, Atom at) newname = get_prop_data(tk->win, atoms[_NET_WM_NAME], atoms[STRING_UTF8], 0) ?: get_prop_data(tk->win, XA_WM_NAME, XA_STRING, 0); if (newname) { + /* It didn't change */ if (tk->name && !strcmp(newname, tk->name)) { XFree(newname); return; @@ -1229,11 +801,12 @@ static void handle_propertynotify(Window win, Atom at) tk->shaded = !tk->shaded; gui_draw_task(tk, TRUE); } - } else if (at == XA_WM_HINTS) { + /* XXX use _NET_WM_ICON */ +// } else if (at == XA_WM_HINTS) { /* some windows set their WM_HINTS icon after mapping */ //if (tk->icon == generic_icon) { - get_task_hinticon(tk); - gui_draw_task(tk, TRUE); +// get_task_hinticon(tk); +// gui_draw_task(tk, TRUE); //} } else if (at == atoms[_NET_WM_DESKTOP]) { if (find_desktop(win) != get_current_desktop()) @@ -1280,12 +853,6 @@ main(int argc, char *argv[]) case ButtonPress: handle_press(ev.xbutton.x, ev.xbutton.y, ev.xbutton.button, ev.xbutton.time); break; - case DestroyNotify: - del_task(ev.xdestroywindow.window); - /* fall through */ - case Expose: - gui_draw_taskbar(); - break; case PropertyNotify: handle_propertynotify(ev.xproperty.window, ev.xproperty.atom); break; @@ -1293,8 +860,7 @@ main(int argc, char *argv[]) printf ("unknown evt type: %d\n", ev.type); */ } } - /* RrThemeFree(theme); - * RrInstanceFree(inst); + /* RrInstanceFree(inst); * XCloseDisplay (dd); return 0; */ -- 2.39.2