Taskbar: thumbnails
This commit is contained in:
@@ -233,6 +233,7 @@ typedef struct Area {
|
||||
// Returns a copy of the tooltip to be displayed for this widget.
|
||||
// The caller takes ownership of the pointer.
|
||||
char *(*_get_tooltip_text)(void *obj);
|
||||
cairo_surface_t *(*_get_tooltip_image)(void *obj);
|
||||
|
||||
// Returns true if the Area handles a mouse event at the given x, y coordinates relative to the window.
|
||||
// Leave this to NULL to use a default implementation.
|
||||
|
||||
@@ -157,7 +157,8 @@ int get_window_desktop(Window win)
|
||||
|
||||
if (best_match < 0)
|
||||
best_match = 0;
|
||||
// fprintf(stderr, "tint2: window %lx %s : viewport %d, (%d, %d)\n", win, get_task(win) ? get_task(win)->title : "??",
|
||||
// fprintf(stderr, "tint2: window %lx %s : viewport %d, (%d, %d)\n", win, get_task(win) ? get_task(win)->title :
|
||||
// "??",
|
||||
// best_match+1, x, y);
|
||||
return best_match;
|
||||
}
|
||||
@@ -190,15 +191,18 @@ int get_window_monitor(Window win)
|
||||
return best_match;
|
||||
}
|
||||
|
||||
void get_window_coordinates(Window win, int *x, int *y, int *w, int *h)
|
||||
gboolean get_window_coordinates(Window win, int *x, int *y, int *w, int *h)
|
||||
{
|
||||
int dummy_int;
|
||||
unsigned ww, wh, bw, bh;
|
||||
Window src;
|
||||
XTranslateCoordinates(server.display, win, server.root_win, 0, 0, x, y, &src);
|
||||
XGetGeometry(server.display, win, &src, &dummy_int, &dummy_int, &ww, &wh, &bw, &bh);
|
||||
if (!XTranslateCoordinates(server.display, win, server.root_win, 0, 0, x, y, &src))
|
||||
return FALSE;
|
||||
if (!XGetGeometry(server.display, win, &src, &dummy_int, &dummy_int, &ww, &wh, &bw, &bh))
|
||||
return FALSE;
|
||||
*w = ww + bw;
|
||||
*h = wh + bh;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean window_is_iconified(Window win)
|
||||
@@ -352,3 +356,39 @@ char *get_window_name(Window win)
|
||||
XFree(text_property.value);
|
||||
return result;
|
||||
}
|
||||
|
||||
cairo_surface_t *get_window_thumbnail(Window win)
|
||||
{
|
||||
int x, y, w, h;
|
||||
if (!get_window_coordinates(win, &x, &y, &w, &h))
|
||||
return NULL;
|
||||
|
||||
int tw, th;
|
||||
th = 128;
|
||||
tw = w * th / h;
|
||||
|
||||
cairo_surface_t *x11_surface =
|
||||
cairo_xlib_surface_create(server.display, win, DefaultVisual(server.display, server.screen), w, h);
|
||||
cairo_surface_t *image_surface = cairo_surface_create_similar_image(x11_surface, CAIRO_FORMAT_ARGB32, tw, th);
|
||||
|
||||
cairo_t *cr = cairo_create(image_surface);
|
||||
cairo_scale(cr, tw/(double)w, th/(double)h);
|
||||
cairo_set_source_surface(cr, x11_surface, 0, 0);
|
||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST);
|
||||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(x11_surface);
|
||||
|
||||
uint32_t *pixels = (uint32_t *)cairo_image_surface_get_data(image_surface);
|
||||
gboolean empty = TRUE;
|
||||
for (int i = 0; empty && i < tw * th; i += 4) {
|
||||
if (pixels[i] & 0xffFFff)
|
||||
empty = FALSE;
|
||||
}
|
||||
if (empty) {
|
||||
cairo_surface_destroy(image_surface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return image_surface;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ int get_window_monitor(Window win);
|
||||
|
||||
void activate_window(Window win);
|
||||
void close_window(Window win);
|
||||
void get_window_coordinates(Window win, int *x, int *y, int *w, int *h);
|
||||
gboolean get_window_coordinates(Window win, int *x, int *y, int *w, int *h);
|
||||
void toggle_window_maximized(Window win);
|
||||
void toggle_window_shade(Window win);
|
||||
void change_window_desktop(Window win, int desktop);
|
||||
@@ -34,5 +34,6 @@ int get_icon_count(gulong *data, int num);
|
||||
gulong *get_best_icon(gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size);
|
||||
|
||||
char *get_window_name(Window win);
|
||||
cairo_surface_t *get_window_thumbnail(Window win);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user