~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to libgeis/backend/grail/geis_ugsubscription_store.c

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file geis_ugsubscription_store.cpp
 
3
 * @brief grail subscription storage
 
4
 */
 
5
/*
 
6
 * Copyright 2012 Canonical Ltd.
 
7
 *
 
8
 * This library is free software: you can redistribute it and/or modify it 
 
9
 * under the terms of the GNU Lesser General Public License version 3
 
10
 * as published by the Free Software Foundation.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful, but 
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
14
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
15
 * PURPOSE.  See the GNU Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
#include "geis_config.h"
 
21
#include "geis_ugsubscription_store.h"
 
22
 
 
23
#include <assert.h>
 
24
#include "geis_logging.h"
 
25
#include <oif/frame_x11.h>
 
26
#include <X11/Xlib.h>
 
27
 
 
28
 
 
29
typedef struct GeisUGSubscription
 
30
{
 
31
  GeisFilter     filter;
 
32
  UFDevice       device;
 
33
  GeisInteger    region_id;
 
34
  UGSubscription ugsub;
 
35
} *GeisUGSubscription;
 
36
 
 
37
static const GeisSize _geis_grail_ugsubscription_store_default_size = 2;
 
38
static const GeisFloat _geis_grail_ugsubscription_store_growth_factor = 1.7;
 
39
 
 
40
 
 
41
/*
 
42
 * Creates a new, empty grail subscription store.
 
43
 */
 
44
GeisUGSubscriptionStore
 
45
geis_ugsubscription_store_new()
 
46
{
 
47
  GeisUGSubscriptionStore store = geis_bag_new(sizeof(struct GeisUGSubscription),
 
48
                                  _geis_grail_ugsubscription_store_default_size,
 
49
                                  _geis_grail_ugsubscription_store_growth_factor);
 
50
  return store;
 
51
}
 
52
 
 
53
 
 
54
/*
 
55
 * Destroys a grail subscription store.
 
56
 */
 
57
void
 
58
geis_ugsubscription_delete(GeisUGSubscriptionStore store)
 
59
{
 
60
  for (GeisSize i = 0; i < geis_bag_count(store); ++i)
 
61
  {
 
62
    grail_subscription_delete(*(UGSubscription*)geis_bag_at(store, i));
 
63
  }
 
64
  geis_bag_delete(store);
 
65
}
 
66
 
 
67
 
 
68
/*
 
69
 * Gets a count of the number of ugsubs in the store.
 
70
 */
 
71
GeisSize
 
72
geis_ugsubscription_count(GeisUGSubscriptionStore store)
 
73
{
 
74
  return geis_bag_count(store);
 
75
}
 
76
 
 
77
 
 
78
/*
 
79
 * Gets a UGSubscription from the store.
 
80
 */
 
81
UGSubscription
 
82
geis_ugsubscription_get_ugsubscription_at(GeisUGSubscriptionStore store,
 
83
                                          GeisSize                index)
 
84
{
 
85
  assert(index < geis_bag_count(store));
 
86
  return ((GeisUGSubscription)geis_bag_at(store, index))->ugsub;
 
87
}
 
88
 
 
89
 
 
90
/*
 
91
 * Gets a UGSubscription from the store.
 
92
 */
 
93
UGSubscription
 
94
geis_ugsubscription_get_ugsubscription(GeisUGSubscriptionStore store,
 
95
                                       GeisFilter              filter,
 
96
                                       UFDevice                device,
 
97
                                       GeisInteger             region_id)
 
98
{
 
99
  UGSubscription ugsub = NULL;
 
100
  for (GeisSize i = 0; i < geis_bag_count(store); ++i)
 
101
  {
 
102
    GeisUGSubscription s = (GeisUGSubscription)geis_bag_at(store, i);
 
103
    if (s->filter == filter && s->device == device && s->region_id == region_id)
 
104
    {
 
105
      ugsub = s->ugsub;
 
106
      break;
 
107
    }
 
108
  }
 
109
 
 
110
  if (!ugsub)
 
111
  {
 
112
    UGStatus ugstatus = grail_subscription_new(&ugsub);
 
113
    if (ugstatus != UGStatusSuccess)
 
114
    {
 
115
      geis_error("failed to create grail subscription");
 
116
      goto final_exit;
 
117
    }
 
118
 
 
119
    ugstatus = grail_subscription_set_property(ugsub,
 
120
                                               UGSubscriptionPropertyDevice,
 
121
                                               &device);
 
122
    if (ugstatus != UGStatusSuccess)
 
123
    {
 
124
      geis_error("failed to set UGSubscription device property");
 
125
    }
 
126
 
 
127
    UFWindowId window_id = frame_x11_create_window_id(region_id);
 
128
    ugstatus = grail_subscription_set_property(ugsub,
 
129
                                               UGSubscriptionPropertyWindow,
 
130
                                               &window_id);
 
131
    if (ugstatus != UGStatusSuccess)
 
132
    {
 
133
      geis_error("failed to set UGSubscription window property");
 
134
    }
 
135
 
 
136
    struct GeisUGSubscription s = {
 
137
      .filter    = filter,
 
138
      .device    = device,
 
139
      .region_id = region_id,
 
140
      .ugsub     = ugsub
 
141
    };
 
142
    geis_bag_append(store, &s);
 
143
  }
 
144
 
 
145
final_exit:
 
146
  return ugsub;
 
147
}
 
148
 
 
149
 
 
150
void
 
151
geis_ugsubscription_release_for_device(GeisUGSubscriptionStore  store,
 
152
                                       GeisFilter               filter,
 
153
                                       UFDevice                 device,
 
154
                                       GeisGrailWindowGrabStore window_grabs)
 
155
{
 
156
  GeisSize i = 0;
 
157
  while (i < geis_bag_count(store))
 
158
  {
 
159
    GeisUGSubscription s = (GeisUGSubscription)geis_bag_at(store, i);
 
160
    if (s->filter == filter && s->device == device)
 
161
    {
 
162
      UFWindowId ufwindow;
 
163
      UGStatus ugstatus;
 
164
      ugstatus = grail_subscription_get_property(s->ugsub,
 
165
                                                 UGSubscriptionPropertyWindow,
 
166
                                                 &ufwindow);
 
167
      if (ugstatus != UGStatusSuccess)
 
168
      {
 
169
        geis_warning("error %d getting subscription window", ugstatus);
 
170
      }
 
171
      else
 
172
      {
 
173
        Window window_id = frame_x11_get_window_id(ufwindow);
 
174
        geis_grail_window_grab_store_ungrab(window_grabs, window_id);
 
175
      }
 
176
 
 
177
      grail_subscription_delete(s->ugsub);
 
178
      geis_bag_remove(store, i);
 
179
    }
 
180
    else
 
181
    {
 
182
      ++i;
 
183
    }
 
184
  }
 
185
}
 
186
 
 
187
 
 
188
/*
 
189
 * Releses a UGSubscription from the store.
 
190
 */
 
191
void
 
192
geis_ugsubscription_release_ugsubscription(GeisUGSubscriptionStore store GEIS_UNUSED,
 
193
                                           UGSubscription          ugsub GEIS_UNUSED)
 
194
{
 
195
}
 
196
 
 
197