2006-10-01 18:30:10 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
Comprehensively rename to Mutter
Code:
All references in the code not related to themes, keybindings, or
GConf were changed from 'metacity' to 'mutter'. This includes, among other
things, strings, comments, the atoms used in the message protocol, and
the envvars used for debugging. The GConf schema file was reduced to
the 3 settings new to mutter.
The overall version was brought up to 2.27 to match current gnome.
Structure:
All files named '*metacity*' were renamed '*mutter*' with appropriate
changes in the automake system. Files removed are
doc/creating_themes, src/themes, doc/metacity-theme.dtd,
metacity.doap. These files will eventually end up in an external
gnome-wm-data module.
Installation location:
On the filesystem the mutter-plugindir was change from
$(libdir)/metacity/plugins/clutter to just $(libdir)/mutter/plugins.
The mutter-plugins.pc.in reflects these changes.
Note:
mutter.desktop.in and mutter-wm.desktop both continue to have
X-GNOME-WMSettingsModule=metacity set. This allows
gnome-control-center to continue using libmetacity.so for
configuration. This is fine since most the general keybindings and wm
settings are being read from /apps/metacity/* in gconf.
2009-06-10 06:29:20 -04:00
|
|
|
/* Mutter window icons */
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2002 Havoc Pennington
|
|
|
|
*
|
|
|
|
* This program 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 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2002-02-09 18:03:52 -05:00
|
|
|
*/
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2002-02-09 18:03:52 -05:00
|
|
|
#include "iconcache.h"
|
2014-12-31 23:39:36 -05:00
|
|
|
|
2011-03-05 19:29:12 -05:00
|
|
|
#include <meta/errors.h>
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
#include <cairo.h>
|
|
|
|
#include <cairo-xlib.h>
|
iconcache: Fix the icon of Kerbel Space Program
Kerbel Space Program, and perhaps some other SDL-based programs, use
a really dumb way of specifying icons, which is totally
non-standards-compliant.
The ICCCM specifies that the icon_pixmap field of WM_HINTS should be a
1-bit-deep Pixmap, but we've seen applications set it to a pixmap of the
root depth as well, so we support that.
Kerbel Space Program seems to use it with a 32-bit depth Pixmap,
signifying ARGB32 (which it is), along with a 1-bit icon_mask, which
crashes us.
Keep in mind that Pixmaps, by definition, have no Visual attached, so
we simply have to make a guess at the correct visual based on the
depth. Do that by assuming that a depth-32 visual always means ARGB32,
which is a pretty safe bet.
2015-02-18 02:37:01 -05:00
|
|
|
#include <cairo-xlib-xrender.h>
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
#include <X11/Xatom.h>
|
iconcache: Fix the icon of Kerbel Space Program
Kerbel Space Program, and perhaps some other SDL-based programs, use
a really dumb way of specifying icons, which is totally
non-standards-compliant.
The ICCCM specifies that the icon_pixmap field of WM_HINTS should be a
1-bit-deep Pixmap, but we've seen applications set it to a pixmap of the
root depth as well, so we support that.
Kerbel Space Program seems to use it with a 32-bit depth Pixmap,
signifying ARGB32 (which it is), along with a 1-bit icon_mask, which
crashes us.
Keep in mind that Pixmaps, by definition, have no Visual attached, so
we simply have to make a guess at the correct visual based on the
depth. Do that by assuming that a depth-32 visual always means ARGB32,
which is a pretty safe bet.
2015-02-18 02:37:01 -05:00
|
|
|
#include <X11/extensions/Xrender.h>
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_largest_sizes (gulong *data,
|
2004-04-19 10:53:14 -04:00
|
|
|
gulong nitems,
|
2002-02-09 18:03:52 -05:00
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
while (nitems > 0)
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
if (nitems < 3)
|
|
|
|
return FALSE; /* no space for w, h */
|
|
|
|
|
|
|
|
w = data[0];
|
|
|
|
h = data[1];
|
|
|
|
|
A load of fixes of issues reported by sparse. Closes bug #152849
2004-09-17 Kjartan Maraas <kmaraas@gnome.org>
* src/bell.c: (meta_bell_flash_screen):
* src/compositor.c:
* src/effects.c: (meta_effects_draw_box_animation):
* src/fixedtip.c: (meta_fixed_tip_show):
* src/frame.c: (find_argb_visual):
* src/frames.c: (unsigned_long_hash), (meta_frames_manage_window),
(meta_frames_apply_shapes):
* src/iconcache.c: (find_largest_sizes), (find_best_size):
* src/keybindings.c: (meta_spawn_command_line_async_on_screen):
* src/main.c: (main):
* src/menu.c: (meta_window_menu_new):
* src/prefs.c: (meta_prefs_get_visual_bell),
(meta_prefs_bell_is_audible), (meta_prefs_get_visual_bell_type),
(meta_prefs_get_action_double_click_titlebar),
(meta_prefs_get_auto_raise), (meta_prefs_get_auto_raise_delay),
(meta_prefs_get_reduced_resources):
* src/screen.c: (meta_create_offscreen_window):
* src/tabpopup.c: (meta_ui_tab_popup_get_selected):
* src/theme-parser.c: (meta_theme_load):
* src/theme.c: (meta_gtk_widget_get_font_desc):
* src/tools/metacity-mag.c: (mouse_press), (begin_area_grab):
* src/util.c: (meta_unsigned_long_hash): A load of fixes of issues
reported by sparse. Closes bug #152849
2004-09-16 19:18:22 -04:00
|
|
|
if (nitems < ((gulong)(w * h) + 2))
|
2002-02-09 18:03:52 -05:00
|
|
|
return FALSE; /* not enough data */
|
|
|
|
|
|
|
|
*width = MAX (w, *width);
|
|
|
|
*height = MAX (h, *height);
|
|
|
|
|
|
|
|
data += (w * h) + 2;
|
|
|
|
nitems -= (w * h) + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_best_size (gulong *data,
|
2004-04-19 10:53:14 -04:00
|
|
|
gulong nitems,
|
2002-02-09 18:03:52 -05:00
|
|
|
int ideal_width,
|
|
|
|
int ideal_height,
|
|
|
|
int *width,
|
|
|
|
int *height,
|
|
|
|
gulong **start)
|
|
|
|
{
|
|
|
|
int best_w;
|
|
|
|
int best_h;
|
|
|
|
gulong *best_start;
|
|
|
|
int max_width, max_height;
|
|
|
|
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
*start = NULL;
|
|
|
|
|
|
|
|
if (!find_largest_sizes (data, nitems, &max_width, &max_height))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (ideal_width < 0)
|
|
|
|
ideal_width = max_width;
|
|
|
|
if (ideal_height < 0)
|
|
|
|
ideal_height = max_height;
|
|
|
|
|
|
|
|
best_w = 0;
|
|
|
|
best_h = 0;
|
|
|
|
best_start = NULL;
|
|
|
|
|
|
|
|
while (nitems > 0)
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
gboolean replace;
|
|
|
|
|
|
|
|
replace = FALSE;
|
|
|
|
|
|
|
|
if (nitems < 3)
|
|
|
|
return FALSE; /* no space for w, h */
|
|
|
|
|
|
|
|
w = data[0];
|
|
|
|
h = data[1];
|
|
|
|
|
A load of fixes of issues reported by sparse. Closes bug #152849
2004-09-17 Kjartan Maraas <kmaraas@gnome.org>
* src/bell.c: (meta_bell_flash_screen):
* src/compositor.c:
* src/effects.c: (meta_effects_draw_box_animation):
* src/fixedtip.c: (meta_fixed_tip_show):
* src/frame.c: (find_argb_visual):
* src/frames.c: (unsigned_long_hash), (meta_frames_manage_window),
(meta_frames_apply_shapes):
* src/iconcache.c: (find_largest_sizes), (find_best_size):
* src/keybindings.c: (meta_spawn_command_line_async_on_screen):
* src/main.c: (main):
* src/menu.c: (meta_window_menu_new):
* src/prefs.c: (meta_prefs_get_visual_bell),
(meta_prefs_bell_is_audible), (meta_prefs_get_visual_bell_type),
(meta_prefs_get_action_double_click_titlebar),
(meta_prefs_get_auto_raise), (meta_prefs_get_auto_raise_delay),
(meta_prefs_get_reduced_resources):
* src/screen.c: (meta_create_offscreen_window):
* src/tabpopup.c: (meta_ui_tab_popup_get_selected):
* src/theme-parser.c: (meta_theme_load):
* src/theme.c: (meta_gtk_widget_get_font_desc):
* src/tools/metacity-mag.c: (mouse_press), (begin_area_grab):
* src/util.c: (meta_unsigned_long_hash): A load of fixes of issues
reported by sparse. Closes bug #152849
2004-09-16 19:18:22 -04:00
|
|
|
if (nitems < ((gulong)(w * h) + 2))
|
2002-02-09 18:03:52 -05:00
|
|
|
break; /* not enough data */
|
|
|
|
|
|
|
|
if (best_start == NULL)
|
|
|
|
{
|
|
|
|
replace = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* work with averages */
|
|
|
|
const int ideal_size = (ideal_width + ideal_height) / 2;
|
|
|
|
int best_size = (best_w + best_h) / 2;
|
|
|
|
int this_size = (w + h) / 2;
|
|
|
|
|
|
|
|
/* larger than desired is always better than smaller */
|
|
|
|
if (best_size < ideal_size &&
|
|
|
|
this_size >= ideal_size)
|
|
|
|
replace = TRUE;
|
|
|
|
/* if we have too small, pick anything bigger */
|
|
|
|
else if (best_size < ideal_size &&
|
|
|
|
this_size > best_size)
|
|
|
|
replace = TRUE;
|
|
|
|
/* if we have too large, pick anything smaller
|
|
|
|
* but still >= the ideal
|
|
|
|
*/
|
|
|
|
else if (best_size > ideal_size &&
|
|
|
|
this_size >= ideal_size &&
|
|
|
|
this_size < best_size)
|
|
|
|
replace = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replace)
|
|
|
|
{
|
|
|
|
best_start = data + 2;
|
|
|
|
best_w = w;
|
|
|
|
best_h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
data += (w * h) + 2;
|
|
|
|
nitems -= (w * h) + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best_start)
|
|
|
|
{
|
|
|
|
*start = best_start;
|
|
|
|
*width = best_w;
|
|
|
|
*height = best_h;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
static cairo_surface_t *
|
|
|
|
argbdata_to_surface (gulong *argb_data, int w, int h)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
int y, x, stride;
|
2015-01-12 15:26:27 -05:00
|
|
|
uint32_t *data;
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
|
2015-01-12 15:26:27 -05:00
|
|
|
stride = cairo_image_surface_get_stride (surface) / sizeof (uint32_t);
|
|
|
|
data = (uint32_t *) cairo_image_surface_get_data (surface);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
/* One could speed this up a lot. */
|
2014-12-31 23:39:36 -05:00
|
|
|
for (y = 0; y < h; y++)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
{
|
2015-01-12 15:26:27 -05:00
|
|
|
uint32_t *p = &data[y * stride + x];
|
2014-12-31 23:39:36 -05:00
|
|
|
gulong *d = &argb_data[y * w + x];
|
|
|
|
*p = *d;
|
|
|
|
}
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
2014-12-31 23:39:36 -05:00
|
|
|
|
2015-10-15 21:57:31 -04:00
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
return surface;
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-12-31 23:39:36 -05:00
|
|
|
read_rgb_icon (MetaDisplay *display,
|
|
|
|
Window xwindow,
|
|
|
|
int ideal_width,
|
|
|
|
int ideal_height,
|
|
|
|
int ideal_mini_width,
|
|
|
|
int ideal_mini_height,
|
|
|
|
cairo_surface_t **icon,
|
|
|
|
cairo_surface_t **mini_icon)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
gulong nitems;
|
|
|
|
gulong bytes_after;
|
|
|
|
int result, err;
|
2008-12-01 17:54:57 -05:00
|
|
|
guchar *data;
|
2002-02-09 18:03:52 -05:00
|
|
|
gulong *best;
|
|
|
|
int w, h;
|
|
|
|
gulong *best_mini;
|
|
|
|
int mini_w, mini_h;
|
2008-12-02 03:15:00 -05:00
|
|
|
gulong *data_as_long;
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-04-06 15:52:44 -04:00
|
|
|
meta_error_trap_push (display);
|
2002-02-09 18:03:52 -05:00
|
|
|
type = None;
|
|
|
|
data = NULL;
|
|
|
|
result = XGetWindowProperty (display->xdisplay,
|
|
|
|
xwindow,
|
2008-05-02 14:49:01 -04:00
|
|
|
display->atom__NET_WM_ICON,
|
2002-02-09 18:03:52 -05:00
|
|
|
0, G_MAXLONG,
|
|
|
|
False, XA_CARDINAL, &type, &format, &nitems,
|
2008-12-01 17:54:57 -05:00
|
|
|
&bytes_after, &data);
|
2010-10-25 14:44:30 -04:00
|
|
|
err = meta_error_trap_pop_with_return (display);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
if (err != Success ||
|
|
|
|
result != Success)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (type != XA_CARDINAL)
|
|
|
|
{
|
|
|
|
XFree (data);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-02 03:15:00 -05:00
|
|
|
data_as_long = (gulong *)data;
|
|
|
|
|
2008-12-01 17:54:57 -05:00
|
|
|
if (!find_best_size (data_as_long, nitems,
|
2002-02-09 18:03:52 -05:00
|
|
|
ideal_width, ideal_height,
|
|
|
|
&w, &h, &best))
|
|
|
|
{
|
|
|
|
XFree (data);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-01 17:54:57 -05:00
|
|
|
if (!find_best_size (data_as_long, nitems,
|
2002-02-09 18:03:52 -05:00
|
|
|
ideal_mini_width, ideal_mini_height,
|
|
|
|
&mini_w, &mini_h, &best_mini))
|
|
|
|
{
|
|
|
|
XFree (data);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
*icon = argbdata_to_surface (best, w, h);
|
|
|
|
*mini_icon = argbdata_to_surface (best_mini, mini_w, mini_h);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_pixmap_geometry (MetaDisplay *display,
|
|
|
|
Pixmap pixmap,
|
|
|
|
int *w,
|
|
|
|
int *h,
|
|
|
|
int *d)
|
|
|
|
{
|
|
|
|
Window root_ignored;
|
|
|
|
int x_ignored, y_ignored;
|
|
|
|
guint width, height;
|
|
|
|
guint border_width_ignored;
|
|
|
|
guint depth;
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
*w = 1;
|
|
|
|
if (h)
|
|
|
|
*h = 1;
|
|
|
|
if (d)
|
|
|
|
*d = 1;
|
|
|
|
|
|
|
|
XGetGeometry (display->xdisplay,
|
|
|
|
pixmap, &root_ignored, &x_ignored, &y_ignored,
|
|
|
|
&width, &height, &border_width_ignored, &depth);
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
*w = width;
|
|
|
|
if (h)
|
|
|
|
*h = height;
|
|
|
|
if (d)
|
|
|
|
*d = depth;
|
|
|
|
}
|
|
|
|
|
iconcache: Fix the icon of Kerbel Space Program
Kerbel Space Program, and perhaps some other SDL-based programs, use
a really dumb way of specifying icons, which is totally
non-standards-compliant.
The ICCCM specifies that the icon_pixmap field of WM_HINTS should be a
1-bit-deep Pixmap, but we've seen applications set it to a pixmap of the
root depth as well, so we support that.
Kerbel Space Program seems to use it with a 32-bit depth Pixmap,
signifying ARGB32 (which it is), along with a 1-bit icon_mask, which
crashes us.
Keep in mind that Pixmaps, by definition, have no Visual attached, so
we simply have to make a guess at the correct visual based on the
depth. Do that by assuming that a depth-32 visual always means ARGB32,
which is a pretty safe bet.
2015-02-18 02:37:01 -05:00
|
|
|
static int
|
|
|
|
standard_pict_format_for_depth (int depth)
|
|
|
|
{
|
|
|
|
switch (depth)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return PictStandardA1;
|
|
|
|
case 24:
|
|
|
|
return PictStandardRGB24;
|
|
|
|
case 32:
|
|
|
|
return PictStandardARGB32;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static XRenderPictFormat *
|
|
|
|
pict_format_for_depth (Display *xdisplay, int depth)
|
|
|
|
{
|
|
|
|
return XRenderFindStandardFormat (xdisplay, standard_pict_format_for_depth (depth));
|
|
|
|
}
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
static cairo_surface_t *
|
|
|
|
surface_from_pixmap (Display *xdisplay, Pixmap xpixmap,
|
|
|
|
int width, int height)
|
2011-03-21 18:45:20 -04:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
Window root_return;
|
|
|
|
int x_ret, y_ret;
|
|
|
|
unsigned int w_ret, h_ret, bw_ret, depth_ret;
|
|
|
|
|
|
|
|
if (!XGetGeometry (xdisplay, xpixmap, &root_return,
|
|
|
|
&x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
|
|
|
|
return NULL;
|
2011-03-21 18:45:20 -04:00
|
|
|
|
iconcache: Fix the icon of Kerbel Space Program
Kerbel Space Program, and perhaps some other SDL-based programs, use
a really dumb way of specifying icons, which is totally
non-standards-compliant.
The ICCCM specifies that the icon_pixmap field of WM_HINTS should be a
1-bit-deep Pixmap, but we've seen applications set it to a pixmap of the
root depth as well, so we support that.
Kerbel Space Program seems to use it with a 32-bit depth Pixmap,
signifying ARGB32 (which it is), along with a 1-bit icon_mask, which
crashes us.
Keep in mind that Pixmaps, by definition, have no Visual attached, so
we simply have to make a guess at the correct visual based on the
depth. Do that by assuming that a depth-32 visual always means ARGB32,
which is a pretty safe bet.
2015-02-18 02:37:01 -05:00
|
|
|
return cairo_xlib_surface_create_with_xrender_format (xdisplay, xpixmap, DefaultScreenOfDisplay (xdisplay),
|
|
|
|
pict_format_for_depth (xdisplay, depth_ret), w_ret, h_ret);
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-12-31 23:39:36 -05:00
|
|
|
try_pixmap_and_mask (MetaDisplay *display,
|
|
|
|
Pixmap src_pixmap,
|
|
|
|
Pixmap src_mask,
|
|
|
|
cairo_surface_t **iconp)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
Display *xdisplay = display->xdisplay;
|
|
|
|
cairo_surface_t *icon, *mask = NULL;
|
2011-03-21 18:45:20 -04:00
|
|
|
int w, h, d;
|
2002-02-09 18:03:52 -05:00
|
|
|
|
|
|
|
if (src_pixmap == None)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
meta_error_trap_push (display);
|
|
|
|
|
2011-03-21 18:45:20 -04:00
|
|
|
get_pixmap_geometry (display, src_pixmap, &w, &h, &d);
|
2014-12-31 23:39:36 -05:00
|
|
|
icon = surface_from_pixmap (xdisplay, src_pixmap, w, h);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
if (icon && src_mask != None)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2011-03-21 18:49:55 -04:00
|
|
|
get_pixmap_geometry (display, src_mask, &w, &h, &d);
|
2014-12-31 23:39:36 -05:00
|
|
|
|
2011-03-21 18:49:55 -04:00
|
|
|
if (d == 1)
|
2014-12-31 23:39:36 -05:00
|
|
|
mask = surface_from_pixmap (xdisplay, src_mask, w, h);
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
|
2010-10-25 14:44:30 -04:00
|
|
|
meta_error_trap_pop (display);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
if (icon && mask)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
cairo_surface_t *masked;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
masked = cairo_surface_create_similar_image (icon,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
2015-02-18 02:33:44 -05:00
|
|
|
cairo_xlib_surface_get_width (icon),
|
|
|
|
cairo_xlib_surface_get_height (icon));
|
2014-12-31 23:39:36 -05:00
|
|
|
cr = cairo_create (masked);
|
|
|
|
|
|
|
|
cairo_set_source_surface (cr, icon, 0, 0);
|
|
|
|
cairo_mask_surface (cr, mask, 0, 0);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (icon);
|
|
|
|
cairo_surface_destroy (mask);
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
icon = masked;
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
|
2014-12-31 23:39:36 -05:00
|
|
|
if (icon)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
*iconp = icon;
|
|
|
|
return TRUE;
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
else
|
2014-12-31 23:39:36 -05:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_kwm_win_icon (MetaDisplay *display,
|
|
|
|
Window xwindow,
|
|
|
|
Pixmap *pixmap,
|
|
|
|
Pixmap *mask)
|
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
gulong nitems;
|
|
|
|
gulong bytes_after;
|
2008-12-01 17:54:57 -05:00
|
|
|
guchar *data;
|
2008-12-02 03:15:00 -05:00
|
|
|
Pixmap *icons;
|
2002-02-09 18:03:52 -05:00
|
|
|
int err, result;
|
|
|
|
|
|
|
|
*pixmap = None;
|
|
|
|
*mask = None;
|
|
|
|
|
2014-04-06 15:52:44 -04:00
|
|
|
meta_error_trap_push (display);
|
2002-02-09 18:03:52 -05:00
|
|
|
icons = NULL;
|
|
|
|
result = XGetWindowProperty (display->xdisplay, xwindow,
|
2008-05-02 14:49:01 -04:00
|
|
|
display->atom__KWM_WIN_ICON,
|
2002-02-09 18:03:52 -05:00
|
|
|
0, G_MAXLONG,
|
|
|
|
False,
|
2008-05-02 14:49:01 -04:00
|
|
|
display->atom__KWM_WIN_ICON,
|
2002-02-09 18:03:52 -05:00
|
|
|
&type, &format, &nitems,
|
2008-12-01 17:54:57 -05:00
|
|
|
&bytes_after, &data);
|
2008-12-02 03:15:00 -05:00
|
|
|
icons = (Pixmap *)data;
|
2002-02-09 18:03:52 -05:00
|
|
|
|
2010-10-25 14:44:30 -04:00
|
|
|
err = meta_error_trap_pop_with_return (display);
|
2002-02-09 18:03:52 -05:00
|
|
|
if (err != Success ||
|
|
|
|
result != Success)
|
|
|
|
return;
|
|
|
|
|
2008-05-02 14:49:01 -04:00
|
|
|
if (type != display->atom__KWM_WIN_ICON)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
|
|
|
XFree (icons);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pixmap = icons[0];
|
|
|
|
*mask = icons[1];
|
|
|
|
|
|
|
|
XFree (icons);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_icon_cache_init (MetaIconCache *icon_cache)
|
|
|
|
{
|
|
|
|
g_return_if_fail (icon_cache != NULL);
|
|
|
|
|
|
|
|
icon_cache->origin = USING_NO_ICON;
|
|
|
|
icon_cache->prev_pixmap = None;
|
2003-11-24 14:09:25 -05:00
|
|
|
icon_cache->prev_mask = None;
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->wm_hints_dirty = TRUE;
|
|
|
|
icon_cache->kwm_win_icon_dirty = TRUE;
|
|
|
|
icon_cache->net_wm_icon_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_icon_cache_property_changed (MetaIconCache *icon_cache,
|
|
|
|
MetaDisplay *display,
|
|
|
|
Atom atom)
|
|
|
|
{
|
2008-05-02 14:49:01 -04:00
|
|
|
if (atom == display->atom__NET_WM_ICON)
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->net_wm_icon_dirty = TRUE;
|
2008-05-02 14:49:01 -04:00
|
|
|
else if (atom == display->atom__KWM_WIN_ICON)
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->kwm_win_icon_dirty = TRUE;
|
|
|
|
else if (atom == XA_WM_HINTS)
|
|
|
|
icon_cache->wm_hints_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_icon_cache_get_icon_invalidated (MetaIconCache *icon_cache)
|
|
|
|
{
|
|
|
|
if (icon_cache->origin <= USING_KWM_WIN_ICON &&
|
|
|
|
icon_cache->kwm_win_icon_dirty)
|
|
|
|
return TRUE;
|
|
|
|
else if (icon_cache->origin <= USING_WM_HINTS &&
|
|
|
|
icon_cache->wm_hints_dirty)
|
|
|
|
return TRUE;
|
|
|
|
else if (icon_cache->origin <= USING_NET_WM_ICON &&
|
|
|
|
icon_cache->net_wm_icon_dirty)
|
|
|
|
return TRUE;
|
2014-07-14 11:23:18 -04:00
|
|
|
else if (icon_cache->origin < USING_FALLBACK_ICON)
|
2002-02-09 18:03:52 -05:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-12-31 23:39:36 -05:00
|
|
|
meta_read_icons (MetaScreen *screen,
|
|
|
|
Window xwindow,
|
|
|
|
MetaIconCache *icon_cache,
|
|
|
|
Pixmap wm_hints_pixmap,
|
|
|
|
Pixmap wm_hints_mask,
|
|
|
|
cairo_surface_t **iconp,
|
|
|
|
int ideal_width,
|
|
|
|
int ideal_height,
|
|
|
|
cairo_surface_t **mini_iconp,
|
|
|
|
int ideal_mini_width,
|
|
|
|
int ideal_mini_height)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
|
|
|
/* Return value is whether the icon changed */
|
|
|
|
|
|
|
|
g_return_val_if_fail (icon_cache != NULL, FALSE);
|
|
|
|
|
|
|
|
*iconp = NULL;
|
|
|
|
*mini_iconp = NULL;
|
|
|
|
|
|
|
|
if (!meta_icon_cache_get_icon_invalidated (icon_cache))
|
|
|
|
return FALSE; /* we have no new info to use */
|
|
|
|
|
|
|
|
/* Our algorithm here assumes that we can't have for example origin
|
|
|
|
* < USING_NET_WM_ICON and icon_cache->net_wm_icon_dirty == FALSE
|
|
|
|
* unless we have tried to read NET_WM_ICON.
|
|
|
|
*
|
|
|
|
* Put another way, if an icon origin is not dirty, then we have
|
|
|
|
* tried to read it at the current size. If it is dirty, then
|
|
|
|
* we haven't done that since the last change.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (icon_cache->origin <= USING_NET_WM_ICON &&
|
|
|
|
icon_cache->net_wm_icon_dirty)
|
|
|
|
{
|
|
|
|
icon_cache->net_wm_icon_dirty = FALSE;
|
|
|
|
|
|
|
|
if (read_rgb_icon (screen->display, xwindow,
|
|
|
|
ideal_width, ideal_height,
|
|
|
|
ideal_mini_width, ideal_mini_height,
|
2014-12-31 23:39:36 -05:00
|
|
|
iconp, mini_iconp))
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
icon_cache->origin = USING_NET_WM_ICON;
|
|
|
|
return TRUE;
|
2002-02-09 18:03:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_cache->origin <= USING_WM_HINTS &&
|
|
|
|
icon_cache->wm_hints_dirty)
|
|
|
|
{
|
2014-07-14 11:29:54 -04:00
|
|
|
Pixmap pixmap;
|
|
|
|
Pixmap mask;
|
|
|
|
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->wm_hints_dirty = FALSE;
|
|
|
|
|
|
|
|
pixmap = wm_hints_pixmap;
|
|
|
|
mask = wm_hints_mask;
|
|
|
|
|
|
|
|
/* We won't update if pixmap is unchanged;
|
|
|
|
* avoids a get_from_drawable() on every geometry
|
|
|
|
* hints change
|
|
|
|
*/
|
|
|
|
if ((pixmap != icon_cache->prev_pixmap ||
|
|
|
|
mask != icon_cache->prev_mask) &&
|
|
|
|
pixmap != None)
|
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
if (try_pixmap_and_mask (screen->display, pixmap, mask, iconp))
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
*mini_iconp = cairo_surface_reference (*iconp);
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->prev_pixmap = pixmap;
|
|
|
|
icon_cache->prev_mask = mask;
|
2014-07-14 11:27:01 -04:00
|
|
|
icon_cache->origin = USING_WM_HINTS;
|
2002-02-09 18:03:52 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_cache->origin <= USING_KWM_WIN_ICON &&
|
|
|
|
icon_cache->kwm_win_icon_dirty)
|
|
|
|
{
|
2014-07-14 11:29:54 -04:00
|
|
|
Pixmap pixmap;
|
|
|
|
Pixmap mask;
|
|
|
|
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->kwm_win_icon_dirty = FALSE;
|
|
|
|
|
|
|
|
get_kwm_win_icon (screen->display, xwindow, &pixmap, &mask);
|
|
|
|
|
|
|
|
if ((pixmap != icon_cache->prev_pixmap ||
|
|
|
|
mask != icon_cache->prev_mask) &&
|
|
|
|
pixmap != None)
|
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
if (try_pixmap_and_mask (screen->display, pixmap, mask, iconp))
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-12-31 23:39:36 -05:00
|
|
|
*mini_iconp = cairo_surface_reference (*iconp);
|
2002-02-09 18:03:52 -05:00
|
|
|
icon_cache->prev_pixmap = pixmap;
|
|
|
|
icon_cache->prev_mask = mask;
|
2014-07-14 11:27:01 -04:00
|
|
|
icon_cache->origin = USING_KWM_WIN_ICON;
|
2002-02-09 18:03:52 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 11:23:18 -04:00
|
|
|
if (icon_cache->origin < USING_FALLBACK_ICON)
|
2002-02-09 18:03:52 -05:00
|
|
|
{
|
2014-07-14 11:27:01 -04:00
|
|
|
icon_cache->origin = USING_FALLBACK_ICON;
|
2014-07-14 12:01:22 -04:00
|
|
|
*iconp = NULL;
|
|
|
|
*mini_iconp = NULL;
|
2002-02-09 18:03:52 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* found nothing new */
|
|
|
|
return FALSE;
|
|
|
|
}
|