From 4ef1fd5beef73e9f49941b6a31bd1ddfaeef863c Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 7 May 2007 06:34:59 +0000 Subject: [PATCH] merge r6134-6144 from trunk --- data/rc.xml.in | 2 + data/xsession/openbox-gnome.desktop | 2 +- data/xsession/openbox-kde.desktop | 2 +- data/xsession/openbox.desktop | 4 +- openbox/action.c | 20 --- openbox/client.c | 23 +-- openbox/focus.c | 215 +++++++++++++++++---------- openbox/popup.c | 222 +++++++++++++--------------- openbox/popup.h | 37 +++-- openbox/prop.c | 4 +- openbox/screen.c | 57 ++++--- render/font.c | 2 +- render/render.c | 2 +- 13 files changed, 304 insertions(+), 288 deletions(-) diff --git a/data/rc.xml.in b/data/rc.xml.in index ca4c7764..66880d7f 100644 --- a/data/rc.xml.in +++ b/data/rc.xml.in @@ -95,6 +95,8 @@ 4 1 + desktop one desktop two desktop three diff --git a/data/xsession/openbox-gnome.desktop b/data/xsession/openbox-gnome.desktop index a7ac098f..da15d1f5 100644 --- a/data/xsession/openbox-gnome.desktop +++ b/data/xsession/openbox-gnome.desktop @@ -1,6 +1,6 @@ [Desktop Entry] Encoding=UTF-8 -Name=Openbox/GNOME +Name=GNOME/Openbox Comment=Use the Openbox window manager inside of the GNOME desktop environment Exec=openbox-gnome-session TryExec=gnome-session diff --git a/data/xsession/openbox-kde.desktop b/data/xsession/openbox-kde.desktop index 456b0df9..1244d8d9 100644 --- a/data/xsession/openbox-kde.desktop +++ b/data/xsession/openbox-kde.desktop @@ -1,6 +1,6 @@ [Desktop Entry] Encoding=UTF-8 -Name=Openbox/KDE +Name=KDE/Openbox Comment=Use the Openbox window manager inside of the K Desktop Environment Exec=openbox-kde-session TryExec=startkde diff --git a/data/xsession/openbox.desktop b/data/xsession/openbox.desktop index 3b4d998e..77de117a 100644 --- a/data/xsession/openbox.desktop +++ b/data/xsession/openbox.desktop @@ -1,8 +1,8 @@ [Desktop Entry] Encoding=UTF-8 Name=Openbox -Comment=Use this session to run Openbox as your desktop environment +Comment=Log in using the Openbox window manager (without a session manager) Exec=openbox -TryExec=openbox-shell +TryExec=openbox Icon=openbox.png Type=XSession diff --git a/openbox/action.c b/openbox/action.c index e056487f..f8b2b7b3 100644 --- a/openbox/action.c +++ b/openbox/action.c @@ -1721,26 +1721,6 @@ void action_moveresize(union ActionData *data) c->frame->size.right, c->area.height + c->frame->size.top + c->frame->size.bottom)); - const gchar *c; - if (corner == prop_atoms.net_wm_moveresize_size_topright) - c = "topright"; - else if (corner == prop_atoms.net_wm_moveresize_size_top) - c = "top"; - else if (corner == prop_atoms.net_wm_moveresize_size_topleft) - c = "topleft"; - else if (corner == prop_atoms.net_wm_moveresize_size_right) - c = "right"; - else if (corner == prop_atoms.net_wm_moveresize_move) - c = "middle"; - else if (corner == prop_atoms.net_wm_moveresize_size_left) - c = "left"; - else if (corner == prop_atoms.net_wm_moveresize_size_bottomright) - c = "bottomright"; - else if (corner == prop_atoms.net_wm_moveresize_size_bottom) - c = "bottom"; - else if (corner == prop_atoms.net_wm_moveresize_size_bottomleft) - c = "bottomleft"; - ob_debug("corner: %s\n", c); } moveresize_start(c, data->any.x, data->any.y, data->any.button, corner); diff --git a/openbox/client.c b/openbox/client.c index 52dfaaa3..3b66a836 100644 --- a/openbox/client.c +++ b/openbox/client.c @@ -2143,9 +2143,11 @@ static void client_change_wm_state(ObClient *self) old = self->wmstate; - if (self->shaded || !self->frame->visible) + if (self->shaded || self->iconic || + (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop)) + { self->wmstate = IconicState; - else + } else self->wmstate = NormalState; if (old != self->wmstate) { @@ -2303,23 +2305,6 @@ gboolean client_should_show(ObClient *self) return FALSE; if (client_normal(self) && screen_showing_desktop) return FALSE; - /* - if (self->transient_for) { - if (self->transient_for != OB_TRAN_GROUP) - return client_should_show(self->transient_for); - else { - GSList *it; - - for (it = self->group->members; it; it = g_slist_next(it)) { - ObClient *c = it->data; - if (c != self && !c->transient_for) { - if (client_should_show(c)) - return TRUE; - } - } - } - } - */ if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL) return TRUE; diff --git a/openbox/focus.c b/openbox/focus.c index eead6000..5d9e0fe4 100644 --- a/openbox/focus.c +++ b/openbox/focus.c @@ -55,14 +55,10 @@ RrColor *color_white; static ObIconPopup *focus_cycle_popup; -static void focus_cycle_destructor(ObClient *client, gpointer data) -{ - /* end cycling if the target disappears. CurrentTime is fine, time won't - be used - */ - if (focus_cycle_target == client) - focus_cycle(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE); -} +static gboolean valid_focus_target(ObClient *ft, + gboolean all_desktops, + gboolean dock_windows); +static void focus_cycle_destructor(ObClient *client, gpointer data); static Window createWindow(Window parent, gulong mask, XSetWindowAttributes *attrib) @@ -289,49 +285,110 @@ void focus_nothing() event_curtime); } -static void popup_cycle(ObClient *c, gboolean show) +static gchar *popup_get_name(ObClient *c, ObClient **nametarget) { + ObClient *p; + gchar *title = NULL; + const gchar *desk = NULL; + gchar *ret; + + /* find our highest direct parent, including non-normal windows */ + for (p = c; p->transient_for && p->transient_for != OB_TRAN_GROUP; + p = p->transient_for); + if (nametarget) *nametarget = p; + + if (c->desktop != DESKTOP_ALL && c->desktop != screen_desktop) + desk = screen_desktop_names[c->desktop]; + + /* use the transient's parent's title/icon if we don't have one */ + if (p != c && !strcmp("", (c->iconic ? c->icon_title : c->title))) + title = g_strdup(p->iconic ? p->icon_title : p->title); + + if (title == NULL) + title = g_strdup(c->iconic ? c->icon_title : c->title); + + if (desk) + ret = g_strdup_printf("%s [%s]", title, desk); + else { + ret = title; + title = NULL; + } + g_free(title); + + return ret; +} + +static void popup_cycle(ObClient *c, gboolean show, + gboolean all_desktops, gboolean dock_windows) +{ + gchar *showtext = NULL; + ObClient *showtarget; + if (!show) { icon_popup_hide(focus_cycle_popup); - } else { + return; + } + + /* do this stuff only when the dialog is first showing */ + if (!focus_cycle_popup->popup->mapped && + !focus_cycle_popup->popup->delay_mapped) + { Rect *a; - ObClient *p; - gchar *text; - gchar *title = NULL; - const gchar *desk = NULL; + gchar **names; + GList *targets = NULL, *it; + gint n = 0, i; + /* position the popup */ a = screen_physical_area_monitor(0); icon_popup_position(focus_cycle_popup, CenterGravity, a->x + a->width / 2, a->y + a->height / 2); - icon_popup_width(focus_cycle_popup, MAX(a->width/3, POPUP_WIDTH)); icon_popup_height(focus_cycle_popup, POPUP_HEIGHT); + icon_popup_min_width(focus_cycle_popup, POPUP_WIDTH); + icon_popup_max_width(focus_cycle_popup, + MAX(a->width/3, POPUP_WIDTH)); - /* find our highest direct parent, including non-normal windows */ - for (p = c; p->transient_for && p->transient_for != OB_TRAN_GROUP; - p = p->transient_for); - if (c->desktop != DESKTOP_ALL && c->desktop != screen_desktop) - desk = screen_desktop_names[c->desktop]; + /* make its width to be the width of all the possible titles */ - /* use the transient's parent's title/icon if we don't have one */ - if (p != c && !strcmp("", (c->iconic ? c->icon_title : c->title))) - title = g_strdup(p->iconic ? p->icon_title : p->title); - /*ptitle = g_strconcat((c->iconic ? c->icon_title : c->title), - " - ", - (p->iconic ? p->icon_title : p->title), - NULL); - */ - if (title == NULL) - title = g_strdup(c->iconic ? c->icon_title : c->title); - if (desk) - text = g_strdup_printf("%s [%s]", title, desk); - else - text = g_strdup(title); + /* build a list of all the valid focus targets */ + for (it = focus_order; it; it = g_list_next(it)) { + ObClient *ft = it->data; + if (valid_focus_target(ft, all_desktops, dock_windows)) { + targets = g_list_prepend(targets, ft); + ++n; + } + } + /* make it null terminated so we can use g_strfreev */ + names = g_new(char*, n+1); + for (it = targets, i = 0; it; it = g_list_next(it), ++i) { + ObClient *ft = it->data; + names[i] = popup_get_name(ft, &showtarget); + + /* little optimization.. save this text so we dont have to get it + again */ + if (ft == c) + showtext = g_strdup(names[i]); + } + names[n] = NULL; - icon_popup_show(focus_cycle_popup, text, client_icon(p, 48, 48)); - g_free(text); - g_free(title); + icon_popup_text_width_to_strings(focus_cycle_popup, names, n); + g_strfreev(names); } + + + if (!showtext) showtext = popup_get_name(c, &showtarget); + icon_popup_show(focus_cycle_popup, showtext, + client_icon(showtarget, 48, 48)); + g_free(showtext); +} + +static void focus_cycle_destructor(ObClient *client, gpointer data) +{ + /* end cycling if the target disappears. CurrentTime is fine, time won't + be used + */ + if (focus_cycle_target == client) + focus_cycle(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE); } void focus_cycle_draw_indicator() @@ -473,47 +530,45 @@ static gboolean valid_focus_target(ObClient *ft, gboolean dock_windows) { gboolean ok = FALSE; - /* we don't use client_can_focus here, because that doesn't let you - focus an iconic window, but we want to be able to, so we just check - if the focus flags on the window allow it, and its on the current - desktop */ + + /* it's on this desktop unless you want all desktops. + + do this check first because it will usually filter out the most + windows */ + ok = (all_desktops || ft->desktop == screen_desktop || + ft->desktop == DESKTOP_ALL); + + /* the window can receive focus somehow */ + ok = ok && (ft->can_focus || ft->focus_notify); + + /* it's the right type of window */ if (dock_windows) - ok = ft->type == OB_CLIENT_TYPE_DOCK; + ok = ok && ft->type == OB_CLIENT_TYPE_DOCK; else - ok = (ft->type == OB_CLIENT_TYPE_NORMAL || - ft->type == OB_CLIENT_TYPE_DIALOG || - ((ft->type == OB_CLIENT_TYPE_TOOLBAR || - ft->type == OB_CLIENT_TYPE_MENU || - ft->type == OB_CLIENT_TYPE_UTILITY) && - /* let alt-tab go to these windows when a window in its group - already has focus ... */ - ((focus_client && ft->group == focus_client->group) || - /* ... or if there are no application windows in its group */ - !client_has_application_group_siblings(ft)))); - ok = ok && (ft->can_focus || ft->focus_notify); - if (!dock_windows && /* use dock windows that skip taskbar too */ - !(ft->type == OB_CLIENT_TYPE_TOOLBAR || /* also, if we actually are */ - ft->type == OB_CLIENT_TYPE_MENU || /* being allowed to target */ - ft->type == OB_CLIENT_TYPE_UTILITY)) /* one of these, don't let */ - ok = ok && !ft->skip_taskbar; /* skip taskbar stop us */ - if (!all_desktops) - ok = ok && (ft->desktop == screen_desktop || - ft->desktop == DESKTOP_ALL); + ok = ok && (ft->type == OB_CLIENT_TYPE_NORMAL || + ft->type == OB_CLIENT_TYPE_DIALOG || + ((ft->type == OB_CLIENT_TYPE_TOOLBAR || + ft->type == OB_CLIENT_TYPE_MENU || + ft->type == OB_CLIENT_TYPE_UTILITY) && + /* let alt-tab go to these windows when a window in its + group already has focus ... */ + ((focus_client && ft->group == focus_client->group) || + /* ... or if there are no application windows in its + group */ + !client_has_application_group_siblings(ft)))); + + /* it's not set to skip the taskbar (unless it is a type that would be + expected to set this hint */ + ok = ok && (!(ft->type == OB_CLIENT_TYPE_DOCK || + ft->type == OB_CLIENT_TYPE_TOOLBAR || + ft->type == OB_CLIENT_TYPE_MENU || + ft->type == OB_CLIENT_TYPE_UTILITY) || + !ft->skip_taskbar); + + /* it's not going to just send fous off somewhere else (modal window) */ ok = ok && ft == client_focus_target(ft); - return ok; -/* - { - GSList *it; - - for (it = ft->transients; it; it = g_slist_next(it)) { - ObClient *c = it->data; - if (frame_visible(c->frame)) - return FALSE; - } - return TRUE; - } -*/ + return ok; } void focus_cycle(gboolean forward, gboolean all_desktops, @@ -568,7 +623,8 @@ void focus_cycle(gboolean forward, gboolean all_desktops, focus_cycle_target = ft; focus_cycle_draw_indicator(); } - popup_cycle(ft, dialog); + /* same arguments as valid_focus_target */ + popup_cycle(ft, dialog, all_desktops, dock_windows); return; } else if (ft != focus_cycle_target) { focus_cycle_target = ft; @@ -590,14 +646,14 @@ done_cycle: if (interactive) { focus_cycle_draw_indicator(); - popup_cycle(ft, FALSE); + popup_cycle(ft, FALSE, FALSE, FALSE); } return; } /* this be mostly ripped from fvwm */ -ObClient *focus_find_directional(ObClient *c, ObDirection dir, +static ObClient *focus_find_directional(ObClient *c, ObDirection dir, gboolean dock_windows) { gint my_cx, my_cy, his_cx, his_cy; @@ -739,7 +795,8 @@ void focus_directional_cycle(ObDirection dir, gboolean dock_windows, } } if (focus_cycle_target) { - popup_cycle(focus_cycle_target, dialog); + /* same arguments as valid_focus_target */ + popup_cycle(focus_cycle_target, dialog, FALSE, dock_windows); if (dialog) return; } @@ -753,7 +810,7 @@ done_cycle: focus_cycle_target = NULL; focus_cycle_draw_indicator(); - popup_cycle(ft, FALSE); + popup_cycle(ft, FALSE, FALSE, FALSE); return; } diff --git a/openbox/popup.c b/openbox/popup.c index b2343867..bf682aaf 100644 --- a/openbox/popup.c +++ b/openbox/popup.c @@ -29,27 +29,14 @@ #include "render/render.h" #include "render/theme.h" -static gboolean popup_show_timeout(gpointer data) -{ - ObPopup *self = data; - - XMapWindow(ob_display, self->bg); - stacking_raise(INTERNAL_AS_WINDOW(self)); - self->mapped = TRUE; - self->delay_mapped = FALSE; - - return FALSE; /* don't repeat */ -} - -ObPopup *popup_new(gboolean hasicon) +ObPopup *popup_new() { XSetWindowAttributes attrib; ObPopup *self = g_new0(ObPopup, 1); self->obwin.type = Window_Internal; - self->hasicon = hasicon; self->gravity = NorthWestGravity; - self->x = self->y = self->w = self->h = 0; + self->x = self->y = self->textw = self->h = 0; self->a_bg = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg); self->a_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label); @@ -63,6 +50,9 @@ ObPopup *popup_new(gboolean hasicon) 0, 0, 1, 1, 0, RrDepth(ob_rr_inst), InputOutput, RrVisual(ob_rr_inst), 0, NULL); + XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->fbwidth); + XSetWindowBorder(ob_display, self->bg, ob_rr_theme->frame_b_color->pixel); + XMapWindow(ob_display, self->text); stacking_add(INTERNAL_AS_WINDOW(self)); @@ -88,10 +78,19 @@ void popup_position(ObPopup *self, gint gravity, gint x, gint y) self->y = y; } -void popup_width(ObPopup *self, gint w) +void popup_text_width(ObPopup *self, gint w) { - self->w = w; - self->maxw = w; + self->textw = w; +} + +void popup_min_width(ObPopup *self, gint minw) +{ + self->minw = minw; +} + +void popup_max_width(ObPopup *self, gint maxw) +{ + self->maxw = maxw; } void popup_height(ObPopup *self, gint h) @@ -103,11 +102,13 @@ void popup_height(ObPopup *self, gint h) self->h = MAX(h, texth); } -void popup_width_to_string(ObPopup *self, gchar *text, gint max) +void popup_text_width_to_string(ObPopup *self, gchar *text) { - self->a_text->texture[0].data.text.string = text; - self->w = RrMinWidth(self->a_text); - self->maxw = max; + if (text[0] != '\0') { + self->a_text->texture[0].data.text.string = text; + self->textw = RrMinWidth(self->a_text); + } else + self->textw = 0; } void popup_height_to_string(ObPopup *self, gchar *text) @@ -115,16 +116,16 @@ void popup_height_to_string(ObPopup *self, gchar *text) self->h = RrMinHeight(self->a_text) + ob_rr_theme->paddingy * 2; } -void popup_width_to_strings(ObPopup *self, gchar **strings, gint num, gint max) +void popup_text_width_to_strings(ObPopup *self, gchar **strings, gint num) { gint i, maxw; maxw = 0; for (i = 0; i < num; ++i) { - popup_width_to_string(self, strings[i], max); - maxw = MAX(maxw, self->w); + popup_text_width_to_string(self, strings[i]); + maxw = MAX(maxw, self->textw); } - self->w = maxw; + self->textw = maxw; } void popup_set_text_align(ObPopup *self, RrJustify align) @@ -132,70 +133,80 @@ void popup_set_text_align(ObPopup *self, RrJustify align) self->a_text->texture[0].data.text.justify = align; } +static gboolean popup_show_timeout(gpointer data) +{ + ObPopup *self = data; + + XMapWindow(ob_display, self->bg); + stacking_raise(INTERNAL_AS_WINDOW(self)); + self->mapped = TRUE; + self->delay_mapped = FALSE; + + return FALSE; /* don't repeat */ +} + void popup_delay_show(ObPopup *self, gulong usec, gchar *text) { gint l, t, r, b; gint x, y, w, h; - gint xpadding, ypadding; - gint textw, texth; - gint iconw; - Rect *area; /* won't go outside this */ - - area = screen_physical_area(); /* XXX this should work quite - good, someone with xinerama, - and different resolutions on - screens? */ + gint emptyx, emptyy; /* empty space between elements */ + gint textx, texty, textw, texth; + gint iconx, icony, iconw, iconh; RrMargins(self->a_bg, &l, &t, &r, &b); - XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->fbwidth); - XSetWindowBorder(ob_display, self->bg, ob_rr_theme->frame_b_color->pixel); - /* set up the textures */ self->a_text->texture[0].data.text.string = text; /* measure the text out */ - RrMinSize(self->a_text, &textw, &texth); - texth += ob_rr_theme->paddingy * 2; - - ypadding = (t+b + ob_rr_theme->paddingy * 2); + if (text[0] != '\0') { + RrMinSize(self->a_text, &textw, &texth); + } else { + textw = 0; + texth = RrMinHeight(self->a_text); + } - /* set the sizes up and reget the text sizes from the calculated - outer sizes */ + /* get the height, which is also used for the icon width */ + emptyy = t + b + ob_rr_theme->paddingy * 2; if (self->h) { h = self->h; - texth = h - ypadding; + texth = h - emptyy; } else - h = texth + ypadding; + h = texth + emptyy; - iconw = (self->hasicon ? texth : 0); - xpadding = l+r + iconw + ob_rr_theme->paddingx * - (self->hasicon ? 3 : 2); + if (self->textw) + textw = self->textw; - if (self->w) - textw = self->w; - w = textw + xpadding; - /* cap it at "maxw" */ + iconx = textx = l + ob_rr_theme->paddingx; + icony = texty = t + ob_rr_theme->paddingy; + + emptyx = l + r + ob_rr_theme->paddingx * 2; + if (self->hasicon) { + iconw = iconh = texth; + textx += iconw + ob_rr_theme->paddingx; + if (textw) + emptyx += ob_rr_theme->paddingx; /* between the icon and text */ + } else + iconw = 0; + + w = textw + emptyx + iconw; + /* cap it at maxw/minw */ if (self->maxw) w = MIN(w, self->maxw); - textw = w - xpadding; + if (self->minw) w = MAX(w, self->minw); + textw = w - emptyx - iconw; /* sanity checks to avoid crashes! */ if (w < 1) w = 1; if (h < 1) h = 1; - if (textw < 1) textw = 1; if (texth < 1) texth = 1; /* set up the x coord */ x = self->x; switch (self->gravity) { - case NorthGravity: - case CenterGravity: - case SouthGravity: + case NorthGravity: case CenterGravity: case SouthGravity: x -= w / 2; break; - case NorthEastGravity: - case EastGravity: - case SouthEastGravity: + case NorthEastGravity: case EastGravity: case SouthEastGravity: x -= w; break; } @@ -203,44 +214,29 @@ void popup_delay_show(ObPopup *self, gulong usec, gchar *text) /* set up the y coord */ y = self->y; switch (self->gravity) { - case WestGravity: - case CenterGravity: - case EastGravity: + case WestGravity: case CenterGravity: case EastGravity: y -= h / 2; break; - case SouthWestGravity: - case SouthGravity: - case SouthEastGravity: + case SouthWestGravity: case SouthGravity: case SouthEastGravity: y -= h; break; } - x=MAX(MIN(x, area->width-w),0); - y=MAX(MIN(y, area->height-h),0); - /* set the windows/appearances up */ XMoveResizeWindow(ob_display, self->bg, x, y, w, h); - - self->a_text->surface.parent = self->a_bg; - self->a_text->surface.parentx = l + iconw + - ob_rr_theme->paddingx * (self->hasicon ? 2 : 1); - self->a_text->surface.parenty = t + ob_rr_theme->paddingy; - XMoveResizeWindow(ob_display, self->text, - l + iconw + ob_rr_theme->paddingx * - (self->hasicon ? 2 : 1), - t + ob_rr_theme->paddingy, textw, texth); - RrPaint(self->a_bg, self->bg, w, h); - RrPaint(self->a_text, self->text, textw, texth); - if (self->hasicon) { - if (iconw < 1) iconw = 1; /* sanity check for crashes */ - if (self->draw_icon) - self->draw_icon(l + ob_rr_theme->paddingx, - t + ob_rr_theme->paddingy, - iconw, texth, self->draw_icon_data); + if (textw) { + self->a_text->surface.parent = self->a_bg; + self->a_text->surface.parentx = textx; + self->a_text->surface.parenty = texty; + XMoveResizeWindow(ob_display, self->text, textx, texty, textw, texth); + RrPaint(self->a_text, self->text, textw, texth); } + if (self->hasicon) + self->draw_icon(iconx, icony, iconw, iconh, self->draw_icon_data); + /* do the actual showing */ if (!self->mapped) { if (usec) { @@ -295,6 +291,7 @@ ObIconPopup *icon_popup_new() RrVisual(ob_rr_inst), 0, NULL); XMapWindow(ob_display, self->icon); + self->popup->hasicon = TRUE; self->popup->draw_icon = icon_popup_draw_icon; self->popup->draw_icon_data = self; @@ -335,21 +332,18 @@ static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, guint vert_inc; guint r, c; gint eachw, eachh; + const guint cols = screen_desktop_layout.columns; + const guint rows = screen_desktop_layout.rows; + const gint linewidth = ob_rr_theme->fbwidth; - eachw = (w - ob_rr_theme->fbwidth - - (screen_desktop_layout.columns * ob_rr_theme->fbwidth)) - / screen_desktop_layout.columns; - eachh = (h - ob_rr_theme->fbwidth - - (screen_desktop_layout.rows * ob_rr_theme->fbwidth)) - / screen_desktop_layout.rows; + eachw = (w - ((cols + 1) * linewidth)) / cols; + eachh = (h - ((rows + 1) * linewidth)) / rows; /* make them squares */ eachw = eachh = MIN(eachw, eachh); /* center */ - px += (w - (screen_desktop_layout.columns * (eachw + ob_rr_theme->fbwidth) + - ob_rr_theme->fbwidth)) / 2; - py += (h - (screen_desktop_layout.rows * (eachh + ob_rr_theme->fbwidth) + - ob_rr_theme->fbwidth)) / 2; + px += (w - (cols * (eachw + linewidth) + linewidth)) / 2; + py += (h - (rows * (eachh + linewidth) + linewidth)) / 2; if (eachw <= 0 || eachh <= 0) return; @@ -360,23 +354,22 @@ static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, case OB_CORNER_TOPLEFT: n = 0; horz_inc = 1; - vert_inc = screen_desktop_layout.columns; + vert_inc = cols; break; case OB_CORNER_TOPRIGHT: - n = screen_desktop_layout.columns - 1; + n = cols - 1; horz_inc = -1; - vert_inc = screen_desktop_layout.columns; + vert_inc = cols; break; case OB_CORNER_BOTTOMRIGHT: - n = screen_desktop_layout.rows * screen_desktop_layout.columns - 1; + n = rows * cols - 1; horz_inc = -1; vert_inc = -screen_desktop_layout.columns; break; case OB_CORNER_BOTTOMLEFT: - n = (screen_desktop_layout.rows - 1) - * screen_desktop_layout.columns; + n = (rows - 1) * cols; horz_inc = 1; - vert_inc = -screen_desktop_layout.columns; + vert_inc = -cols; break; default: g_assert_not_reached(); @@ -386,23 +379,22 @@ static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, switch (screen_desktop_layout.start_corner) { case OB_CORNER_TOPLEFT: n = 0; - horz_inc = screen_desktop_layout.rows; + horz_inc = rows; vert_inc = 1; break; case OB_CORNER_TOPRIGHT: - n = screen_desktop_layout.rows - * (screen_desktop_layout.columns - 1); - horz_inc = -screen_desktop_layout.rows; + n = rows * (cols - 1); + horz_inc = -rows; vert_inc = 1; break; case OB_CORNER_BOTTOMRIGHT: - n = screen_desktop_layout.rows * screen_desktop_layout.columns - 1; - horz_inc = -screen_desktop_layout.rows; + n = rows * cols - 1; + horz_inc = -rows; vert_inc = -1; break; case OB_CORNER_BOTTOMLEFT: - n = screen_desktop_layout.rows - 1; - horz_inc = screen_desktop_layout.rows; + n = rows - 1; + horz_inc = rows; vert_inc = -1; break; default: @@ -414,11 +406,9 @@ static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, } rown = n; - for (r = 0, y = 0; r < screen_desktop_layout.rows; - ++r, y += eachh + ob_rr_theme->fbwidth) + for (r = 0, y = 0; r < rows; ++r, y += eachh + linewidth) { - for (c = 0, x = 0; c < screen_desktop_layout.columns; - ++c, x += eachw + ob_rr_theme->fbwidth) + for (c = 0, x = 0; c < cols; ++c, x += eachw + linewidth) { RrAppearance *a; diff --git a/openbox/popup.h b/openbox/popup.h index 4b07bd9d..0bf2f500 100644 --- a/openbox/popup.h +++ b/openbox/popup.h @@ -45,8 +45,9 @@ struct _ObPopup gint gravity; gint x; gint y; - gint w; + gint textw; gint h; + gint minw; gint maxw; gboolean mapped; gboolean delay_mapped; @@ -74,7 +75,7 @@ struct _ObPagerPopup RrAppearance *unhilight; }; -ObPopup *popup_new(gboolean hasicon); +ObPopup *popup_new(); void popup_free(ObPopup *self); /*! Position the popup. The gravity rules are not the same X uses for windows, @@ -85,11 +86,13 @@ void popup_free(ObPopup *self); void popup_position(ObPopup *self, gint gravity, gint x, gint y); /*! Set the sizes for the popup. When set to 0, the size will be based on the text size. */ -void popup_width(ObPopup *self, gint w); void popup_height(ObPopup *self, gint w); -void popup_width_to_string(ObPopup *self, gchar *text, gint max); +void popup_min_width(ObPopup *self, gint minw); +void popup_max_width(ObPopup *self, gint maxw); +void popup_text_width(ObPopup *self, gint w); +void popup_text_width_to_string(ObPopup *self, gchar *text); void popup_height_to_string(ObPopup *self, gchar *text); -void popup_width_to_strings(ObPopup *self, gchar **strings, gint num,gint max); +void popup_text_width_to_strings(ObPopup *self, gchar **strings, gint num); void popup_set_text_align(ObPopup *self, RrJustify align); @@ -108,12 +111,14 @@ void icon_popup_delay_show(ObIconPopup *self, gulong usec, gchar *text, const struct _ObClientIcon *icon); #define icon_popup_hide(p) popup_hide((p)->popup) #define icon_popup_position(p, g, x, y) popup_position((p)->popup,(g),(x),(y)) -#define icon_popup_width(p, w) popup_width((p)->popup,(w)) +#define icon_popup_text_width(p, w) popup_text_width((p)->popup,(w)) #define icon_popup_height(p, h) popup_height((p)->popup,(h)) -#define icon_popup_width_to_string(p, s, n, m) \ - popup_width_to_string((p)->popup,(s),(n),(m)) -#define icon_popup_width_to_strings(p, s, n, m) \ - popup_width_to_strings((p)->popup,(s),(n),(m)) +#define icon_popup_min_width(p, m) popup_min_width((p)->popup,(m)) +#define icon_popup_max_width(p, m) popup_max_width((p)->popup,(m)) +#define icon_popup_text_width_to_string(p, s) \ + popup_text_width_to_string((p)->popup,(s)) +#define icon_popup_text_width_to_strings(p, s, n) \ + popup_text_width_to_strings((p)->popup,(s),(n)) #define icon_popup_set_text_align(p, j) popup_set_text_align((p)->popup,(j)) ObPagerPopup *pager_popup_new(); @@ -124,12 +129,14 @@ void pager_popup_delay_show(ObPagerPopup *self, gulong usec, gchar *text, guint desk); #define pager_popup_hide(p) popup_hide((p)->popup) #define pager_popup_position(p, g, x, y) popup_position((p)->popup,(g),(x),(y)) -#define pager_popup_width(p, w) popup_width((p)->popup,(w)) +#define pager_popup_text_width(p, w) popup_text_width((p)->popup,(w)) #define pager_popup_height(p, h) popup_height((p)->popup,(h)) -#define pager_popup_width_to_string(p, s, n, m) \ - popup_width_to_string((p)->popup,(s),(n),(m)) -#define pager_popup_width_to_strings(p, s, n, m) \ - popup_width_to_strings((p)->popup,(s),(n),(m)) +#define pager_popup_min_width(p, m) popup_min_width((p)->popup,(m)) +#define pager_popup_max_width(p, m) popup_max_width((p)->popup,(m)) +#define pager_popup_text_width_to_string(p, s) \ + popup_text_width_to_string((p)->popup,(s)) +#define pager_popup_text_width_to_strings(p, s, n) \ + popup_text_width_to_strings((p)->popup,(s),(n)) #define pager_popup_set_text_align(p, j) popup_set_text_align((p)->popup,(j)) #endif diff --git a/openbox/prop.c b/openbox/prop.c index 6bd05cc6..0485045e 100644 --- a/openbox/prop.c +++ b/openbox/prop.c @@ -328,7 +328,7 @@ gboolean prop_get_strings_locale(Window win, Atom prop, gchar ***ret) if (get_all(win, prop, prop_atoms.string, 8, (guchar**)&raw, &num)) { p = raw; - while (p < raw + num - 1) { + while (p < raw + num) { ++count; strs = g_slist_append(strs, p); p += strlen(p) + 1; /* next string */ @@ -377,7 +377,7 @@ gboolean prop_get_strings_utf8(Window win, Atom prop, gchar ***ret) if (get_all(win, prop, prop_atoms.utf8, 8, (guchar**)&raw, &num)) { p = raw; - while (p < raw + num - 1) { + while (p < raw + num) { ++count; strs = g_slist_append(strs, p); p += strlen(p) + 1; /* next string */ diff --git a/openbox/screen.c b/openbox/screen.c index b0c3286a..1faf521e 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -299,34 +299,29 @@ gboolean screen_annex(const gchar *program_name) void screen_startup(gboolean reconfig) { - GSList *it; - guint i; - - desktop_cycle_popup = pager_popup_new(FALSE); - pager_popup_height(desktop_cycle_popup, POPUP_HEIGHT); + if (!reconfig) { + guint i, numnames; + gchar **names; + GSList *it; - if (!reconfig) /* get the initial size */ screen_resize(); - /* get the names */ - if (PROP_GETSS(RootWindow(ob_display, ob_screen), - net_desktop_names, utf8, &screen_desktop_names)) - for (i = 0; screen_desktop_names[i]; ++i); - else - i = 0; - for (it = g_slist_nth(config_desktops_names, i); it; - it = g_slist_next(it), ++i) - { - screen_desktop_names = g_renew(gchar*, screen_desktop_names, i + 2); - screen_desktop_names[i+1] = NULL; - screen_desktop_names[i] = g_strdup(it->data); + /* get the desktop names */ + numnames = g_slist_length(config_desktops_names); + names = g_new(gchar*, numnames + 1); + names[numnames] = NULL; + for (i = 0, it = config_desktops_names; it; ++i, it = g_slist_next(it)) + names[i] = g_strdup(it->data); + + /* set the root window property */ + PROP_SETSS(RootWindow(ob_display, ob_screen), net_desktop_names,names); + + g_strfreev(names); } - /* then set the names */ - PROP_SETSS(RootWindow(ob_display, ob_screen), - net_desktop_names, screen_desktop_names); - g_strfreev(screen_desktop_names); - screen_desktop_names = NULL; + + desktop_cycle_popup = pager_popup_new(FALSE); + pager_popup_height(desktop_cycle_popup, POPUP_HEIGHT); if (!reconfig) screen_num_desktops = 0; @@ -480,7 +475,7 @@ void screen_set_desktop(guint num, gboolean dofocus) /* show windows before hiding the rest to lessen the enter/leave events */ - /* show/hide windows from top to bottom */ + /* show windows from top to bottom */ for (it = stacking_list; it; it = g_list_next(it)) { if (WINDOW_IS_CLIENT(it->data)) { ObClient *c = it->data; @@ -629,6 +624,8 @@ void screen_desktop_popup(guint d, gboolean show) a = screen_physical_area_monitor(0); pager_popup_position(desktop_cycle_popup, CenterGravity, a->x + a->width / 2, a->y + a->height / 2); + pager_popup_max_width(desktop_cycle_popup, + MAX(a->width/3, POPUP_WIDTH)); pager_popup_show(desktop_cycle_popup, screen_desktop_names[d], d); } } @@ -876,10 +873,10 @@ void screen_update_desktop_names() if (PROP_GETSS(RootWindow(ob_display, ob_screen), net_desktop_names, utf8, &screen_desktop_names)) - for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i); + for (i = 0; screen_desktop_names[i] && i < screen_num_desktops; ++i); else i = 0; - if (i <= screen_num_desktops) { + if (i < screen_num_desktops) { screen_desktop_names = g_renew(gchar*, screen_desktop_names, screen_num_desktops + 1); screen_desktop_names[screen_num_desktops] = NULL; @@ -888,11 +885,9 @@ void screen_update_desktop_names() } /* resize the pager for these names */ - pager_popup_width_to_strings(desktop_cycle_popup, - screen_desktop_names, - screen_num_desktops, - MAX(screen_physical_area_monitor(0)->width/3, - POPUP_WIDTH)); + pager_popup_text_width_to_strings(desktop_cycle_popup, + screen_desktop_names, + screen_num_desktops); } void screen_show_desktop(gboolean show, gboolean restore_focus) diff --git a/render/font.c b/render/font.c index 50b4208f..1ca1b768 100644 --- a/render/font.c +++ b/render/font.c @@ -137,7 +137,7 @@ static void font_measure_full(const RrFont *f, const gchar *str, pango_layout_set_text(f->layout, str, -1); pango_layout_set_width(f->layout, -1); pango_layout_get_pixel_extents(f->layout, NULL, &rect); - *x = rect.width + ABS(shadow_x); + *x = rect.width + ABS(shadow_x) + 4 /* we put a 2 px edge on each side */; *y = rect.height + ABS(shadow_y); } diff --git a/render/render.c b/render/render.c index 2755e667..d34ddccb 100644 --- a/render/render.c +++ b/render/render.c @@ -369,7 +369,7 @@ gint RrMinWidth(RrAppearance *a) a->texture[i].data.text.string, a->texture[i].data.text.shadow_offset_x, a->texture[i].data.text.shadow_offset_y); - w = MAX(w, m->width + 4); + w = MAX(w, m->width); g_free(m); break; case RR_TEXTURE_RGBA: -- 2.39.2