Commit 39df2122 authored by Havoc Pennington's avatar Havoc Pennington Committed by Havoc Pennington
Browse files

add support for a mini icon in the titlebar (update_icon): re-enable

2001-09-15  Havoc Pennington  <hp@pobox.com>

	* src/window.c: add support for a mini icon in the titlebar
	(update_icon): re-enable support for _NET_WM_ICON

	* src/session.c (save_state): add an ferror check when writing
	session file
parent 2830c9d7
2001-09-15 Havoc Pennington <hp@pobox.com>
* src/window.c: add support for a mini icon in the titlebar
(update_icon): re-enable support for _NET_WM_ICON
* src/session.c (save_state): add an ferror check when writing
session file
2001-09-11 Havoc Pennington <hp@pobox.com>
* src/main.c (usage): exit with error code on usage() (kind of
wrong for --help, but oh well).
2001-09-11 Havoc Pennington <hp@pobox.com>
* src/window.c: fix up handling of text properties, so we
......
......@@ -62,8 +62,13 @@ if test "$found_sm" = "true"; then
AC_DEFINE(HAVE_SM)
fi
# Check for shaped window extension
AC_CHECK_LIB(Xext, XShapeCombineMask, AC_DEFINE(HAVE_SHAPE_EXT),,$METACITY_LIBS)
AM_CONDITIONAL(HAVE_SM, test "$found_sm" = "true")
MSM_CFLAGS=$METACITY_CFLAGS
MSM_LIBS=$METACITY_LIBS
AC_SUBST(MSM_CFLAGS)
AC_SUBST(MSM_LIBS)
HOST_ALIAS=$host_alias
AC_SUBST(HOST_ALIAS)
......@@ -72,6 +77,7 @@ AC_OUTPUT([
Makefile
src/Makefile
src/wm-tester/Makefile
src/msm/Makefile
])
SUBDIRS=wm-tester
if HAVE_SM
SM_SUBDIRS=msm
else
SM_SUBDIRS=
endif
SUBDIRS=wm-tester $(SM_SUBDIRS)
INCLUDES=@METACITY_CFLAGS@ -DMETACITY_LIBEXECDIR=\"$(libexecdir)\" -DHOST_ALIAS=\"@HOST_ALIAS@\"
......
......@@ -60,6 +60,22 @@ meta_core_get_frame_flags (Display *xdisplay,
return meta_frame_get_flags (window->frame);
}
GdkPixbuf*
meta_core_get_mini_icon (Display *xdisplay,
Window frame_xwindow)
{
MetaDisplay *display;
MetaWindow *window;
display = meta_display_for_x_display (xdisplay);
window = meta_display_lookup_x_window (display, frame_xwindow);
if (window == NULL || window->frame == NULL)
meta_bug ("No such frame window 0x%lx!\n", frame_xwindow);
return window->mini_icon;
}
void
meta_core_queue_frame_resize (Display *xdisplay,
Window frame_xwindow)
......
......@@ -36,6 +36,9 @@ void meta_core_get_frame_size (Display *xdisplay,
MetaFrameFlags meta_core_get_frame_flags (Display *xdisplay,
Window frame_xwindow);
GdkPixbuf* meta_core_get_mini_icon (Display *xdisplay,
Window frame_xwindow);
void meta_core_queue_frame_resize (Display *xdisplay,
Window frame_xwindow);
......
......@@ -1740,11 +1740,78 @@ meta_frames_expose_event (GtkWidget *widget,
if (frame->layout)
{
PangoRectangle layout_rect;
int x, y, icon_x, icon_y;
GdkPixbuf *icon;
int icon_w, icon_h;
int area_w, area_h;
#define ICON_TEXT_SPACING 2
icon = meta_core_get_mini_icon (gdk_display,
frame->xwindow);
icon_w = gdk_pixbuf_get_width (icon);
icon_h = gdk_pixbuf_get_height (icon);
pango_layout_get_pixel_extents (frame->layout,
NULL,
&layout_rect);
/* corner of whole title area */
x = fgeom.title_rect.x + frames->props->text_border.left;
y = fgeom.title_rect.y + frames->props->text_border.top;
area_w = fgeom.title_rect.width -
frames->props->text_border.left -
frames->props->text_border.right;
area_h = fgeom.title_rect.height -
frames->props->text_border.top -
frames->props->text_border.bottom;
/* center icon vertically */
icon_y = y + MAX ((area_h - icon_h) / 2, 0);
/* center text vertically */
y = y + MAX ((area_h - layout_rect.height) / 2, 0);
/* Center icon + text combo */
icon_x = x + MAX ((area_w - layout_rect.width - icon_w - ICON_TEXT_SPACING) / 2, 0);
x = icon_x + icon_w + ICON_TEXT_SPACING;
gdk_gc_set_clip_rectangle (layout_gc, &clip);
{
/* grumble, render_to_drawable_alpha does not accept a clip
* mask, so we have to go through some BS
*/
GdkRectangle pixbuf_rect;
GdkRectangle draw_rect;
pixbuf_rect.x = icon_x;
pixbuf_rect.y = icon_y;
pixbuf_rect.width = icon_w;
pixbuf_rect.height = icon_h;
if (gdk_rectangle_intersect (&clip, &pixbuf_rect, &draw_rect))
{
gdk_pixbuf_render_to_drawable_alpha (icon,
frame->window,
draw_rect.x - pixbuf_rect.x,
draw_rect.y - pixbuf_rect.y,
draw_rect.x, draw_rect.y,
draw_rect.width,
draw_rect.height,
GDK_PIXBUF_ALPHA_FULL,
128,
GDK_RGB_DITHER_NORMAL,
0, 0);
}
}
gdk_draw_layout (frame->window,
layout_gc,
fgeom.title_rect.x + frames->props->text_border.left,
fgeom.title_rect.y + frames->props->text_border.top,
x, y,
frame->layout);
gdk_gc_set_clip_rectangle (layout_gc, NULL);
}
......
......@@ -42,7 +42,7 @@ static void
usage (void)
{
g_print ("metacity [--disable-sm] [--sm-client-id=ID] [--display=DISPLAY]\n");
exit (0);
exit (1);
}
int
......
......@@ -288,25 +288,9 @@ msm_client_set_property_taking_ownership (MsmClient *client,
SmProp *prop)
{
/* we own prop which should be freed with SmFreeProperty() */
GList *list;
if (prop->name == NULL)
{
SmFreeProperty (prop);
return;
}
list = proplist_find_link_by_name (client->properties, prop->name);
if (list)
{
SmFreeProperty (list->data);
list->data = prop;
}
else
{
client->properties = g_list_prepend (client->properties,
prop);
}
/* pass our ownership into the proplist */
client->properties = proplist_replace (client->properties, prop);
/* update pieces of the client struct */
if (strcmp (prop->name, "SmRestartStyleHint") == 0)
......@@ -323,15 +307,7 @@ void
msm_client_unset_property (MsmClient *client,
const char *name)
{
GList *list;
list = proplist_find_link_by_name (client->properties, name);
if (list)
{
SmFreeProperty (list->data);
client->properties = g_list_delete_link (client->properties,
list);
}
client->properties = proplist_delete (client->properties, name);
/* Return to default values */
if (strcmp (name, "SmRestartStyleHint") == 0)
......
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* this file Copyright (C) 2001 Havoc Pennington
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
/* FIXME implementation contains a bunch of cut-and-paste from GtkFrame
* that would be easy to avoid by adding an "int space_before_label_widget"
* in GtkFrame that was overridden by subclasses.
*/
/* FIXME the whole GtkFrame derivation idea is fucked since we can't get
* the click event on the arrow.
*/
#define ARROW_SIZE 12
#define ARROW_PAD 2
enum {
PROP_0,
PROP_DISCLOSED,
PROP_LAST
};
static void gtk_disclosure_box_class_init (GtkDisclosureBoxClass *klass);
static void gtk_disclosure_box_init (GtkDisclosureBox *box);
static void gtk_disclosure_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_disclosure_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_disclosure_box_paint (GtkWidget *widget,
GdkRectangle *area);
static gint gtk_disclosure_box_expose (GtkWidget *widget,
GdkEventExpose *event);
static void gtk_disclosure_box_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_disclosure_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_frame_compute_child_allocation (GtkFrame *frame,
GtkAllocation *child_allocation);
GType
gtk_disclosure_box_get_type (void)
{
static GType disclosure_box_type = 0;
if (!disclosure_box_type)
{
static const GtkTypeInfo disclosure_box_info =
{
"GtkDisclosureBox",
sizeof (GtkDisclosureBox),
sizeof (GtkDisclosureBoxClass),
(GtkClassInitFunc) gtk_disclosure_box_class_init,
(GtkObjectInitFunc) gtk_disclosure_box_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
disclosure_box_type = gtk_type_unique (gtk_box_get_type (), &disclosure_box_info);
}
return disclosure_box_type;
}
static void
gtk_disclosure_box_class_init (GtkDisclosureBoxClass *class)
{
GtkWidgetClass *widget_class;
GObjectClass *gobject_class;
GtkContainerClass *container_class;
GtkFrameClass *frame_class;
gobject_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
container_class = GTK_CONTAINER_CLASS (class);
frame_class = GTK_FRAME_CLASS (class);
gobject_class->set_property = gtk_disclosure_box_set_property;
gobject_class->get_property = gtk_disclosure_box_get_property;
widget_class->size_request = gtk_disclosure_box_size_request;
widget_class->size_allocate = gtk_disclosure_box_size_allocate;
widget_class->expose_event = gtk_disclosure_box_expose;
}
static void
gtk_disclosure_box_init (GtkDisclosureBox *disclosure_box)
{
}
GtkWidget*
gtk_disclosure_box_new (const char *label)
{
return g_object_new (GTK_TYPE_DISCLOSURE_BOX, "label", label, NULL);
}
static void
gtk_disclosure_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkDisclosureBox *box;
box = GTK_DISCLOSURE_BOX (object);
switch (prop_id)
{
case PROP_DISCLOSED:
gtk_disclosure_box_set_disclosed (box,
g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_disclosure_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkDisclosureBox *box;
box = GTK_DISCLOSURE_BOX (object);
switch (prop_id)
{
case PROP_DISCLOSED:
g_value_set_boolean (value, box->disclosed);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
void
gtk_disclosure_box_set_disclosed (GtkDisclosureBox *box,
gboolean disclosed)
{
g_return_if_fail (GTK_IS_DISCLOSURE_BOX (box));
disclosed = disclosed != FALSE;
if (disclosed != box->disclosed)
{
box->disclosed = disclosed;
gtk_widget_queue_resize (GTK_WIDGET (box));
}
}
gboolean
gtk_disclosure_box_get_disclosed (GtkDisclosureBox *box)
{
g_return_val_if_fail (GTK_IS_DISCLOSURE_BOX (box), FALSE);
return box->disclosed;
}
static void
gtk_disclosure_box_paint (GtkWidget *widget,
GdkRectangle *area)
{
GtkFrame *frame;
gint x, y, width, height;
if (GTK_WIDGET_DRAWABLE (widget))
{
frame = GTK_FRAME (widget);
x = frame->child_allocation.x - widget->style->xthickness;
y = frame->child_allocation.y - widget->style->ythickness;
width = frame->child_allocation.width + 2 * widget->style->xthickness;
height = frame->child_allocation.height + 2 * widget->style->ythickness;
if (frame->label_widget)
{
GtkRequisition child_requisition;
gfloat xalign;
gint height_extra;
gint x2;
gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = frame->label_xalign;
else
xalign = 1 - frame->label_xalign;
height_extra = MAX (0, child_requisition.height - widget->style->xthickness);
y -= height_extra * (1 - frame->label_yalign);
height += height_extra * (1 - frame->label_yalign);
x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
gtk_paint_shadow_gap (widget->style, widget->window,
GTK_STATE_NORMAL, frame->shadow_type,
area, widget, "frame",
x, y, width, height,
GTK_POS_TOP,
x2 + ARROW_SIZE + ARROW_PAD * 2, child_requisition.width + 2 * LABEL_PAD);
gtk_paint_arrow (widget->style, widget->window,
widget->state, GTK_SHADOW_OUT,
area, widget, "arrow",
GTK_DISCLOSURE_BOX (widget)->disclosed ?
GTK_ARROW_RIGHT : GTK_ARROW_DOWN,
TRUE,
x2 + ARROW_PAD, y, ARROW_SIZE, ARROW_SIZE);
}
else
gtk_paint_shadow (widget->style, widget->window,
GTK_STATE_NORMAL, frame->shadow_type,
area, widget, "frame",
x, y, width, height);
}
}
static gboolean
gtk_disclosure_box_expose (GtkWidget *widget,
GdkEventExpose *event)
{
if (GTK_WIDGET_DRAWABLE (widget))
{
gtk_disclosure_box_paint (widget, &event->area);
(* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
}
return FALSE;
}
static void
gtk_disclosure_box_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkFrame *frame = GTK_FRAME (widget);
GtkBin *bin = GTK_BIN (widget);
GtkRequisition child_requisition;
if (frame->label_widget && GTK_WIDGET_VISIBLE (frame->label_widget))
{
gtk_widget_size_request (frame->label_widget, &child_requisition);
requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD + ARROW_SIZE + ARROW_PAD * 2;
requisition->height =
MAX (0, child_requisition.height - GTK_WIDGET (widget)->style->xthickness);
}
else
{
requisition->width = 0;
requisition->height = 0;
}
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
{
gtk_widget_size_request (bin->child, &child_requisition);
requisition->width = MAX (requisition->width, child_requisition.width);
requisition->height += child_requisition.height;
}
requisition->width += (GTK_CONTAINER (widget)->border_width +
GTK_WIDGET (widget)->style->xthickness) * 2;
requisition->height += (GTK_CONTAINER (widget)->border_width +
GTK_WIDGET (widget)->style->ythickness) * 2;
}
static void
gtk_disclosure_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkFrame *frame = GTK_FRAME (widget);
GtkBin *bin = GTK_BIN (widget);
GtkAllocation new_allocation;
widget->allocation = *allocation;
gtk_frame_compute_child_allocation (frame, &new_allocation);
/* If the child allocation changed, that means that the frame is drawn
* in a new place, so we must redraw the entire widget.
*/
if (GTK_WIDGET_MAPPED (widget) &&
(new_allocation.x != frame->child_allocation.x ||
new_allocation.y != frame->child_allocation.y ||
new_allocation.width != frame->child_allocation.width ||
new_allocation.height != frame->child_allocation.height))
gtk_widget_queue_clear (widget);
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
gtk_widget_size_allocate (bin->child, &new_allocation);
frame->child_allocation = new_allocation;
if (frame->label_widget && GTK_WIDGET_VISIBLE (frame->label_widget))
{
GtkRequisition child_requisition;
GtkAllocation child_allocation;
gfloat xalign;
gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = frame->label_xalign;
else
xalign = 1 - frame->label_xalign;
child_allocation.x = frame->child_allocation.x + LABEL_SIDE_PAD +
(frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD + ARROW_SIZE + ARROW_PAD * 2;
child_allocation.width = child_requisition.width;
child_allocation.y = frame->child_allocation.y - child_requisition.height;
child_allocation.height = child_requisition.height;
gtk_widget_size_allocate (frame->label_widget, &child_allocation);
}
}
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* this file Copyright (C) 2001 Havoc Pennington
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with