X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Futil%2Fwindow.c;h=ac2b40016e9d9f581a250f69aee16e17e7e65ef8;hb=9a6f8801012c62445afd308a733aed5fc3bb7716;hp=730178d78cc0430ef0a63643777bdaf1cf110618;hpb=0357305cec0f78ba4d4717467025ead6be25ce0c;p=chaz%2Ftint2 diff --git a/src/util/window.c b/src/util/window.c index 730178d..ac2b400 100644 --- a/src/util/window.c +++ b/src/util/window.c @@ -3,7 +3,7 @@ * Tint2 : common windows function * * Copyright (C) 2007 PÃ¥l Staurland (staura@gmail.com) -* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) +* Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 @@ -33,223 +33,326 @@ #include "window.h" #include "server.h" #include "panel.h" +#include "taskbar.h" void set_active (Window win) { - send_event32 (win, server.atom._NET_ACTIVE_WINDOW, 2, 0); + send_event32 (win, server.atom._NET_ACTIVE_WINDOW, 2, CurrentTime, 0); } void set_desktop (int desktop) { - send_event32 (server.root_win, server.atom._NET_CURRENT_DESKTOP, desktop, 0); + send_event32 (server.root_win, server.atom._NET_CURRENT_DESKTOP, desktop, 0, 0); } void windows_set_desktop (Window win, int desktop) { - send_event32 (win, server.atom._NET_WM_DESKTOP, desktop, 2); + send_event32 (win, server.atom._NET_WM_DESKTOP, desktop, 2, 0); } void set_close (Window win) { - send_event32 (win, server.atom._NET_CLOSE_WINDOW, 0, 2); + send_event32 (win, server.atom._NET_CLOSE_WINDOW, 0, 2, 0); } void window_toggle_shade (Window win) { - send_event32 (win, server.atom._NET_WM_STATE, 2, server.atom._NET_WM_STATE_SHADED); + send_event32 (win, server.atom._NET_WM_STATE, 2, server.atom._NET_WM_STATE_SHADED, 0); +} + + +void window_maximize_restore (Window win) +{ + send_event32 (win, server.atom._NET_WM_STATE, 2, server.atom._NET_WM_STATE_MAXIMIZED_VERT, 0); + send_event32 (win, server.atom._NET_WM_STATE, 2, server.atom._NET_WM_STATE_MAXIMIZED_HORZ, 0); } int window_is_hidden (Window win) { - Window window; - Atom *at; - int count, i; - - if (XGetTransientForHint(server.dsp, win, &window) != 0) { - if (window) { - return 1; - } - } - - at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count); - for (i = 0; i < count; i++) { - if (at[i] == server.atom._NET_WM_STATE_SKIP_PAGER || at[i] == server.atom._NET_WM_STATE_SKIP_TASKBAR) { - XFree(at); - return 1; - } - } - XFree(at); - - at = server_get_property (win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, &count); - for (i = 0; i < count; i++) { - if (at[i] == server.atom._NET_WM_WINDOW_TYPE_DOCK || at[i] == server.atom._NET_WM_WINDOW_TYPE_DESKTOP || at[i] == server.atom._NET_WM_WINDOW_TYPE_TOOLBAR || at[i] == server.atom._NET_WM_WINDOW_TYPE_MENU || at[i] == server.atom._NET_WM_WINDOW_TYPE_SPLASH) { - XFree(at); - return 1; - } - } - XFree(at); + Window window; + Atom *at; + int count, i; + + at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count); + for (i = 0; i < count; i++) { + if (at[i] == server.atom._NET_WM_STATE_SKIP_TASKBAR) { + XFree(at); + return 1; + } + // do not add transient_for windows if the transient window is already in the taskbar + window=win; + while ( XGetTransientForHint(server.dsp, window, &window) ) { + if ( task_get_tasks(window) ) { + XFree(at); + return 1; + } + } + } + XFree(at); + + at = server_get_property (win, server.atom._NET_WM_WINDOW_TYPE, XA_ATOM, &count); + for (i = 0; i < count; i++) { + if (at[i] == server.atom._NET_WM_WINDOW_TYPE_DOCK || at[i] == server.atom._NET_WM_WINDOW_TYPE_DESKTOP || at[i] == server.atom._NET_WM_WINDOW_TYPE_TOOLBAR || at[i] == server.atom._NET_WM_WINDOW_TYPE_MENU || at[i] == server.atom._NET_WM_WINDOW_TYPE_SPLASH) { + XFree(at); + return 1; + } + } + XFree(at); for (i=0 ; i < nb_panel ; i++) { - if (panel1[i].main_win == win) + if (panel1[i].main_win == win) { return 1; + } } - // specification - // Windows with neither _NET_WM_WINDOW_TYPE nor WM_TRANSIENT_FOR set - // MUST be taken as top-level window. - return 0; + // specification + // Windows with neither _NET_WM_WINDOW_TYPE nor WM_TRANSIENT_FOR set + // MUST be taken as top-level window. + return 0; } int window_get_desktop (Window win) { - return get_property32(win, server.atom._NET_WM_DESKTOP, XA_CARDINAL); + return get_property32(win, server.atom._NET_WM_DESKTOP, XA_CARDINAL); } int window_get_monitor (Window win) { - int i, x, y; - Window src; - - XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, &x, &y, &src); - x += 2; - y += 2; - for (i = 0; i < server.nb_monitor; i++) { - if (x >= server.monitor[i].x && x <= (server.monitor[i].x + server.monitor[i].width)) - if (y >= server.monitor[i].y && y <= (server.monitor[i].y + server.monitor[i].height)) - break; - } + int i, x, y; + Window src; + + XTranslateCoordinates(server.dsp, win, server.root_win, 0, 0, &x, &y, &src); + x += 2; + y += 2; + for (i = 0; i < server.nb_monitor; i++) { + if (x >= server.monitor[i].x && x <= (server.monitor[i].x + server.monitor[i].width)) + if (y >= server.monitor[i].y && y <= (server.monitor[i].y + server.monitor[i].height)) + break; + } - //printf("window %lx : ecran %d, (%d, %d)\n", win, i, x, y); - if (i == server.nb_monitor) return 0; - else return i; + //printf("window %lx : ecran %d, (%d, %d)\n", win, i, x, y); + if (i == server.nb_monitor) return 0; + else return i; } int window_is_iconified (Window win) { - return (IconicState == get_property32(win, server.atom.WM_STATE, server.atom.WM_STATE)); + // EWMH specification : minimization of windows use _NET_WM_STATE_HIDDEN. + // WM_STATE is not accurate for shaded window and in multi_desktop mode. + Atom *at; + int count, i; + at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count); + for (i = 0; i < count; i++) { + if (at[i] == server.atom._NET_WM_STATE_HIDDEN) { + XFree(at); + return 1; + } + } + XFree(at); + return 0; +} + + +int window_is_urgent (Window win) +{ + Atom *at; + int count, i; + + at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count); + for (i = 0; i < count; i++) { + if (at[i] == server.atom._NET_WM_STATE_DEMANDS_ATTENTION) { + XFree(at); + return 1; + } + } + XFree(at); + return 0; +} + + +int window_is_skip_taskbar (Window win) +{ + Atom *at; + int count, i; + + at = server_get_property(win, server.atom._NET_WM_STATE, XA_ATOM, &count); + for (i=0; i num || w * h == 0) break; - count++; - } + int count, pos, w, h; + + count = 0; + pos = 0; + while (pos+2 < num) { + w = data[pos++]; + h = data[pos++]; + pos += w * h; + if (pos > num || w <= 0 || h <= 0) break; + count++; + } - return count; + return count; } -long *get_best_icon (long *data, int icon_count, int num, int *iw, int *ih, int best_icon_size) +gulong *get_best_icon (gulong *data, int icon_count, int num, int *iw, int *ih, int best_icon_size) { - int width[icon_count], height[icon_count], pos, i, w, h; - long *icon_data[icon_count]; + int width[icon_count], height[icon_count], pos, i, w, h; + gulong *icon_data[icon_count]; + + /* List up icons */ + pos = 0; + i = icon_count; + while (i--) { + w = data[pos++]; + h = data[pos++]; + if (pos + w * h > num) break; + + width[i] = w; + height[i] = h; + icon_data[i] = &data[pos]; + + pos += w * h; + } - /* List up icons */ - pos = 0; - i = icon_count; - while (i--) { - w = data[pos++]; - h = data[pos++]; - if (pos + w * h > num) break; + /* Try to find exact size */ + int icon_num = -1; + for (i = 0; i < icon_count; i++) { + if (width[i] == best_icon_size) { + icon_num = i; + break; + } + } - width[i] = w; - height[i] = h; - icon_data[i] = &data[pos]; + /* Take the biggest or whatever */ + if (icon_num < 0) { + int highest = 0; + for (i = 0; i < icon_count; i++) { + if (width[i] > highest) { + icon_num = i; + highest = width[i]; + } + } + } - pos += w * h; - } + *iw = width[icon_num]; + *ih = height[icon_num]; + return icon_data[icon_num]; +} - /* Try to find exact size */ - int icon_num = -1; - for (i = 0; i < icon_count; i++) { - if (width[i] == best_icon_size) { - icon_num = i; - break; - } - } - /* Take the biggest or whatever */ - if (icon_num < 0) { - int highest = 0; - for (i = 0; i < icon_count; i++) { - if (width[i] > highest) { - icon_num = i; - highest = width[i]; - } - } - } +void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len) +{ + PangoRectangle rect_ink, rect; - *iw = width[icon_num]; - *ih = height[icon_num]; - return icon_data[icon_num]; + Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); + + cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height); + cairo_t *c = cairo_create (cs); + + PangoLayout *layout = pango_cairo_create_layout (c); + pango_layout_set_font_description (layout, font); + pango_layout_set_text (layout, text, len); + + pango_layout_get_pixel_extents(layout, &rect_ink, &rect); + *height_ink = rect_ink.height; + *height = rect.height; + //printf("dimension : %d - %d\n", rect_ink.height, rect.height); + + g_object_unref (layout); + cairo_destroy (c); + cairo_surface_destroy (cs); + XFreePixmap (server.dsp, pmap); } -void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len) +void get_text_size2(PangoFontDescription *font, int *height_ink, int *height, int *width, int panel_height, int panel_with, char *text, int len) { - PangoRectangle rect_ink, rect; + PangoRectangle rect_ink, rect; - Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); + Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); - cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height); - cairo_t *c = cairo_create (cs); + cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_with); + cairo_t *c = cairo_create (cs); - PangoLayout *layout = pango_cairo_create_layout (c); - pango_layout_set_font_description (layout, font); - pango_layout_set_text (layout, text, len); + PangoLayout *layout = pango_cairo_create_layout (c); + pango_layout_set_font_description (layout, font); + pango_layout_set_text (layout, text, len); - pango_layout_get_pixel_extents(layout, &rect_ink, &rect); - *height_ink = rect_ink.height; - *height = rect.height; - //printf("dimension : %d - %d\n", rect_ink.height, rect.height); + pango_layout_get_pixel_extents(layout, &rect_ink, &rect); + *height_ink = rect_ink.height; + *height = rect.height; + *width = rect.width; + //printf("dimension : %d - %d\n", rect_ink.height, rect.height); - g_object_unref (layout); - cairo_destroy (c); - cairo_surface_destroy (cs); - XFreePixmap (server.dsp, pmap); + g_object_unref (layout); + cairo_destroy (c); + cairo_surface_destroy (cs); + XFreePixmap (server.dsp, pmap); }