~timo-jyrinki/bamf/ubuntu-0.2.124.1

« back to all changes in this revision

Viewing changes to src/bamf-xutils.c

  • Committer: Timo Jyrinki
  • Date: 2012-11-14 07:15:04 UTC
  • mfrom: (235.1.49)
  • Revision ID: timo.jyrinki@canonical.com-20121114071504-s8umq349iaf7lwq6
* New upstream release.
  - Includes all previous cherry-picks
  - remerge libbamf, Makefile: don't export private symbols (factory 
    and matcher)
  - BamfMatcher: force a view as closed or not-closed on proper 
    signals. This avoids that a view that is opened is actually 
    marked as closed when really it's running. (LP: #925421)
  - Daemon, BamfApplication: Use the default icon if there is not 
    one defined in the desktop file. (LP: #886778)
  - BamfMatcher: don't reopen windows when iterating on view's 
    list, add tests.
  - Build fixes, including enabling introspection.
  - BamfMatcher: add support for libreoffice Base, and libreoffice 
    matching tests (LP: #1063862)

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
  return xdisplay;
45
45
}
46
46
 
47
 
char *
48
 
bamf_xutils_get_window_hint (Window xid, const char *atom_name, Atom type)
 
47
static void
 
48
bamf_xutils_get_string_window_hint_and_type (Window xid, const char *atom_name,
 
49
                                             gchar** return_hint, Atom* return_type)
49
50
{
50
51
  Display *XDisplay;
51
 
  Atom atom;
52
 
  char *hint = NULL;
53
 
  Atom result_type;
54
52
  gint format;
55
53
  gulong numItems;
56
54
  gulong bytesAfter;
 
55
  Atom type;
57
56
  unsigned char *buffer;
58
 
  gboolean close_display = FALSE;
59
 
 
60
 
  g_return_val_if_fail ((xid != 0), NULL);
61
 
  g_return_val_if_fail (atom_name, NULL);
62
 
 
 
57
  gboolean close_display;
 
58
 
 
59
  if (return_hint)
 
60
    *return_hint = NULL;
 
61
 
 
62
  if (return_type)
 
63
    *return_type = AnyPropertyType;
 
64
 
 
65
  g_return_if_fail (xid != 0);
 
66
  g_return_if_fail (return_hint || return_type);
 
67
 
 
68
  close_display = FALSE;
63
69
  XDisplay = get_xdisplay (&close_display);
64
70
 
65
71
  if (!XDisplay)
66
72
  {
67
73
    g_warning ("%s: Unable to get a valid XDisplay", G_STRFUNC);
68
 
    return NULL;
 
74
    return;
69
75
  }
70
76
 
71
 
  atom = XInternAtom (XDisplay, atom_name, FALSE);
72
 
 
73
 
  int result = XGetWindowProperty (XDisplay,
74
 
                                   xid,
75
 
                                   atom,
76
 
                                   0,
77
 
                                   G_MAXINT,
78
 
                                   FALSE,
79
 
                                   type,
80
 
                                   &result_type,
81
 
                                   &format,
82
 
                                   &numItems,
83
 
                                   &bytesAfter,
84
 
                                   &buffer);
 
77
  int result = XGetWindowProperty (XDisplay,  xid,
 
78
                                   gdk_x11_get_xatom_by_name (atom_name),
 
79
                                   0,  G_MAXINT, False, AnyPropertyType,
 
80
                                   &type, &format, &numItems,
 
81
                                   &bytesAfter, &buffer);
85
82
 
86
83
  if (close_display)
87
84
    XCloseDisplay (XDisplay);
88
85
 
89
86
  if (result == Success && numItems > 0)
90
87
    {
91
 
      if (buffer && buffer[0] != '\0')
92
 
        hint = g_strdup ((char*) buffer);
 
88
      if (return_type)
 
89
        *return_type = type;
 
90
 
 
91
      if (return_hint && buffer && buffer[0] != '\0')
 
92
        {
 
93
          if (type == XA_STRING || type == gdk_x11_get_xatom_by_name("UTF8_STRING"))
 
94
            *return_hint = g_strdup ((char*) buffer);
 
95
        }
93
96
 
94
97
      XFree (buffer);
95
98
    }
 
99
}
 
100
 
 
101
char *
 
102
bamf_xutils_get_string_window_hint (Window xid, const char *atom_name)
 
103
{
 
104
  gchar *hint = NULL;
 
105
  bamf_xutils_get_string_window_hint_and_type (xid, atom_name, &hint, NULL);
96
106
 
97
107
  return hint;
98
108
}
99
109
 
100
110
void
101
 
bamf_xutils_set_window_hint (Window xid, const char *atom_name, Atom type, const char *data)
 
111
bamf_xutils_set_string_window_hint (Window xid, const char *atom_name, const char *value)
102
112
{
103
113
  Display *XDisplay;
 
114
  Atom type;
104
115
  gboolean close_display = FALSE;
105
116
 
106
117
  g_return_if_fail (xid != 0);
107
118
  g_return_if_fail (atom_name);
108
 
  g_return_if_fail (data);
109
 
  
 
119
  g_return_if_fail (value);
 
120
 
110
121
  XDisplay = get_xdisplay (&close_display);
111
122
 
112
123
  if (!XDisplay)
115
126
    return;
116
127
  }
117
128
 
118
 
  XChangeProperty (XDisplay,
119
 
                   xid,
120
 
                   XInternAtom (XDisplay,
121
 
                   atom_name,
122
 
                   FALSE),
123
 
                   type,
124
 
                   8,
125
 
                   PropModeReplace,
126
 
                   (unsigned char *) data,
127
 
                   strlen (data));
 
129
  bamf_xutils_get_string_window_hint_and_type (xid, atom_name, NULL, &type);
 
130
 
 
131
  if (type == AnyPropertyType)
 
132
    {
 
133
      type = XA_STRING;
 
134
    }
 
135
  else if (type != XA_STRING && type != gdk_x11_get_xatom_by_name("UTF8_STRING"))
 
136
    {
 
137
      g_error ("Impossible to set the atom %s on Window %lu", atom_name, xid);
 
138
      return;
 
139
    }
 
140
 
 
141
  XChangeProperty (XDisplay, xid, gdk_x11_get_xatom_by_name (atom_name),
 
142
                   type, 8, PropModeReplace, (unsigned char *) value, strlen (value));
128
143
 
129
144
  if (close_display)
130
145
    XCloseDisplay (XDisplay);