/[rdesktop]/sourceforge.net/trunk/rdesktop/ewmhints.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/ewmhints.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1199 by astrand, Mon Mar 27 08:17:34 2006 UTC revision 1476 by jsorg71, Fri Jul 11 03:55:52 2008 UTC
# Line 4  Line 4 
4     Support functions for Extended Window Manager Hints,     Support functions for Extended Window Manager Hints,
5     http://www.freedesktop.org/wiki/Standards_2fwm_2dspec     http://www.freedesktop.org/wiki/Standards_2fwm_2dspec
6    
7     Copyright (C) Peter Astrand <astrand@cendio.se> 2005     Copyright 2005 Peter Astrand <astrand@cendio.se> for Cendio AB
8         Copyright 2007 Pierre Ossman <ossman@cendio.se> for Cendio AB
9    
10     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.     (at your option) any later version.
14      
15     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.     GNU General Public License for more details.
19      
20     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
22     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Line 34  extern Display *g_display; Line 35  extern Display *g_display;
35    
36  static Atom g_net_wm_state_maximized_vert_atom, g_net_wm_state_maximized_horz_atom,  static Atom g_net_wm_state_maximized_vert_atom, g_net_wm_state_maximized_horz_atom,
37          g_net_wm_state_hidden_atom, g_net_wm_name_atom, g_utf8_string_atom,          g_net_wm_state_hidden_atom, g_net_wm_name_atom, g_utf8_string_atom,
38          g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom, g_net_wm_state_modal_atom;          g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom,
39            g_net_wm_state_modal_atom, g_net_wm_icon_atom, g_net_wm_state_above_atom;
40    
41  Atom g_net_wm_state_atom, g_net_wm_desktop_atom;  Atom g_net_wm_state_atom, g_net_wm_desktop_atom;
42    
# Line 184  ewmh_init() Line 186  ewmh_init()
186                  XInternAtom(g_display, "_NET_WM_STATE_SKIP_TASKBAR", False);                  XInternAtom(g_display, "_NET_WM_STATE_SKIP_TASKBAR", False);
187          g_net_wm_state_skip_pager_atom = XInternAtom(g_display, "_NET_WM_STATE_SKIP_PAGER", False);          g_net_wm_state_skip_pager_atom = XInternAtom(g_display, "_NET_WM_STATE_SKIP_PAGER", False);
188          g_net_wm_state_modal_atom = XInternAtom(g_display, "_NET_WM_STATE_MODAL", False);          g_net_wm_state_modal_atom = XInternAtom(g_display, "_NET_WM_STATE_MODAL", False);
189            g_net_wm_state_above_atom = XInternAtom(g_display, "_NET_WM_STATE_ABOVE", False);
190          g_net_wm_state_atom = XInternAtom(g_display, "_NET_WM_STATE", False);          g_net_wm_state_atom = XInternAtom(g_display, "_NET_WM_STATE", False);
191          g_net_wm_desktop_atom = XInternAtom(g_display, "_NET_WM_DESKTOP", False);          g_net_wm_desktop_atom = XInternAtom(g_display, "_NET_WM_DESKTOP", False);
192          g_net_wm_name_atom = XInternAtom(g_display, "_NET_WM_NAME", False);          g_net_wm_name_atom = XInternAtom(g_display, "_NET_WM_NAME", False);
193            g_net_wm_icon_atom = XInternAtom(g_display, "_NET_WM_ICON", False);
194          g_utf8_string_atom = XInternAtom(g_display, "UTF8_STRING", False);          g_utf8_string_atom = XInternAtom(g_display, "UTF8_STRING", False);
195  }  }
196    
# Line 202  ewmh_get_window_state(Window w) Line 206  ewmh_get_window_state(Window w)
206          unsigned char *prop_return;          unsigned char *prop_return;
207          uint32 *return_words;          uint32 *return_words;
208          unsigned long item;          unsigned long item;
209          BOOL maximized_vert, maximized_horz, hidden;          RD_BOOL maximized_vert, maximized_horz, hidden;
210    
211          maximized_vert = maximized_horz = hidden = False;          maximized_vert = maximized_horz = hidden = False;
212    
# Line 240  ewmh_modify_state(Window wnd, int add, A Line 244  ewmh_modify_state(Window wnd, int add, A
244          int result;          int result;
245          unsigned long nitems;          unsigned long nitems;
246          unsigned char *props;          unsigned char *props;
247          uint32 state;          uint32 state = WithdrawnState;
248    
249          /* The spec states that the window manager must respect any          /* The spec states that the window manager must respect any
250             _NET_WM_STATE attributes on a withdrawn window. In order words, we             _NET_WM_STATE attributes on a withdrawn window. In order words, we
# Line 253  ewmh_modify_state(Window wnd, int add, A Line 257  ewmh_modify_state(Window wnd, int add, A
257                  XFree(props);                  XFree(props);
258          }          }
259    
260          if ((result < 0) || !nitems || (state == WithdrawnState))          if (state == WithdrawnState)
261          {          {
262                  if (add)                  if (add)
263                  {                  {
# Line 422  ewmh_set_window_modal(Window wnd) Line 426  ewmh_set_window_modal(Window wnd)
426                  return -1;                  return -1;
427          return 0;          return 0;
428  }  }
429    
430    void
431    ewmh_set_icon(Window wnd, int width, int height, const char *rgba_data)
432    {
433            unsigned long nitems, i;
434            unsigned char *props;
435            uint32 *cur_set, *new_set;
436            uint32 *icon;
437    
438            cur_set = NULL;
439            new_set = NULL;
440    
441            if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) >= 0)
442            {
443                    cur_set = (uint32 *) props;
444    
445                    for (i = 0; i < nitems;)
446                    {
447                            if (cur_set[i] == width && cur_set[i + 1] == height)
448                                    break;
449    
450                            i += 2 + cur_set[i] * cur_set[i + 1];
451                    }
452    
453                    if (i != nitems)
454                            icon = cur_set + i;
455                    else
456                    {
457                            new_set = xmalloc((nitems + width * height + 2) * 4);
458                            memcpy(new_set, cur_set, nitems * 4);
459                            icon = new_set + nitems;
460                            nitems += width * height + 2;
461                    }
462            }
463            else
464            {
465                    new_set = xmalloc((width * height + 2) * 4);
466                    icon = new_set;
467                    nitems = width * height + 2;
468            }
469    
470            icon[0] = width;
471            icon[1] = height;
472    
473            /* Convert RGBA -> ARGB */
474            for (i = 0; i < width * height; i++)
475            {
476                    icon[i + 2] =
477                            rgba_data[i * 4 + 3] << 24 |
478                            ((rgba_data[i * 4 + 0] << 16) & 0x00FF0000) |
479                            ((rgba_data[i * 4 + 1] << 8) & 0x0000FF00) |
480                            ((rgba_data[i * 4 + 2] << 0) & 0x000000FF);
481            }
482    
483            XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32,
484                            PropModeReplace, (unsigned char *) (new_set ? new_set : cur_set), nitems);
485    
486            if (cur_set)
487                    XFree(cur_set);
488            if (new_set)
489                    xfree(new_set);
490    }
491    
492    void
493    ewmh_del_icon(Window wnd, int width, int height)
494    {
495            unsigned long nitems, i, icon_size;
496            unsigned char *props;
497            uint32 *cur_set, *new_set;
498    
499            cur_set = NULL;
500            new_set = NULL;
501    
502            if (get_property_value(wnd, "_NET_WM_ICON", 10000, &nitems, &props, 1) < 0)
503                    return;
504    
505            cur_set = (uint32 *) props;
506    
507            for (i = 0; i < nitems;)
508            {
509                    if (cur_set[i] == width && cur_set[i + 1] == height)
510                            break;
511    
512                    i += 2 + cur_set[i] * cur_set[i + 1];
513            }
514    
515            if (i == nitems)
516                    goto out;
517    
518            icon_size = width * height + 2;
519            new_set = xmalloc((nitems - icon_size) * 4);
520    
521            if (i != 0)
522                    memcpy(new_set, cur_set, i * 4);
523            if (i != nitems - icon_size)
524                    memcpy(new_set + i * 4, cur_set + i * 4 + icon_size, nitems - icon_size);
525    
526            nitems -= icon_size;
527    
528            XChangeProperty(g_display, wnd, g_net_wm_icon_atom, XA_CARDINAL, 32,
529                            PropModeReplace, (unsigned char *) new_set, nitems);
530    
531            xfree(new_set);
532    
533          out:
534            XFree(cur_set);
535    }
536    
537    int
538    ewmh_set_window_above(Window wnd)
539    {
540            if (ewmh_modify_state(wnd, 1, g_net_wm_state_above_atom, 0) < 0)
541                    return -1;
542            return 0;
543    }
544    
545  #endif /* MAKE_PROTO */  #endif /* MAKE_PROTO */
546    

Legend:
Removed from v.1199  
changed lines
  Added in v.1476

  ViewVC Help
Powered by ViewVC 1.1.26