~ted/unity/menu-ref

702.3.1 by Michael Terry
add modelines and fix up some inconsistent tabbings
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
2
/*
572.5.2 by Jay Taoko
* Adding license to files
3
 * Copyright (C) 2010 Canonical Ltd
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 3 as
7
 * published by the Free Software Foundation.
8
 *
9
 * This program is distributed in the hope that it will be useful,
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
572.5.2 by Jay Taoko
* Adding license to files
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * Authored by: Jason Smith <jason.smith@canonical.com>
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
18
 */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
19
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
20
#include <glib.h>
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
21
#include <sstream>
1826.4.4 by Andrea Azzarone
Ops.
22
#include "PluginAdapter.h"
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
23
#include "UScreen.h"
1826.4.2 by Andrea Azzarone
Merge trunk.
24
25
#include <NuxCore/Logger.h>
2324.2.4 by Marco Trevisan (Treviño)
WindowManager: make it introspectable, implementation in PluginAdapter.
26
#include <UnityCore/Variant.h>
1826.4.2 by Andrea Azzarone
Merge trunk.
27
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
28
namespace
29
{
1224.3.5 by Tim Penhey
Use the new logger.
30
31
nux::logging::Logger logger("unity.plugin");
32
1818.5.1 by Andrea Azzarone
Disables window auto-maximise functionality if the monitor resolution is greater then 1024x600.
33
const int THRESHOLD_HEIGHT = 600;
34
const int THRESHOLD_WIDTH = 1024;
35
1224.3.5 by Tim Penhey
Use the new logger.
36
}
37
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
38
PluginAdapter* PluginAdapter::_default = 0;
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
39
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
40
#define MAXIMIZABLE (CompWindowActionMaximizeHorzMask & CompWindowActionMaximizeVertMask & CompWindowActionResizeMask)
41
1091 by Jason Smith
decorate/undecorate using compiz display
42
#define MWM_HINTS_FUNCTIONS     (1L << 0)
43
#define MWM_HINTS_DECORATIONS   (1L << 1)
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
44
#define MWM_HINTS_UNDECORATED_UNITY 0x80
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
45
#define _XA_MOTIF_WM_HINTS    "_MOTIF_WM_HINTS"
1091 by Jason Smith
decorate/undecorate using compiz display
46
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
47
/* static */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
48
PluginAdapter*
49
PluginAdapter::Default()
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
50
{
711.1.1 by Jason Smith
Random autohide fixes
51
  if (!_default)
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
52
    return 0;
711.1.1 by Jason Smith
Random autohide fixes
53
  return _default;
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
54
}
55
56
/* static */
57
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
58
PluginAdapter::Initialize(CompScreen* screen)
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
59
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
60
  _default = new PluginAdapter(screen);
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
61
}
62
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
63
PluginAdapter::PluginAdapter(CompScreen* screen) :
64
  m_Screen(screen),
65
  m_ExpoActionList(0),
1423.1.3 by Sam Spilsbury
Simplify the input focus restore stuff and move that into
66
  m_ScaleActionList(0),
1435 by Sam Spilsbury
Merge lp:~unity-team/unity/unity.fullscreen_windows_paint_on_top
67
  _in_show_desktop (false),
1423.1.3 by Sam Spilsbury
Simplify the input focus restore stuff and move that into
68
  _last_focused_window(nullptr)
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
69
{
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
70
  _spread_state = false;
1858.17.56 by Marco Trevisan (Treviño)
PluginAdapter: added IsScaleActiveForGroup to get if scale is running for a window subset
71
  _spread_windows_state = false;
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
72
  _expo_state = false;
1315.7.1 by Marco Trevisan (Treviño)
PluginAdapter: suport compiz_screen_viewport_switch_{started,ended} signals
73
  _vp_switch_started = false;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
74
1011.1.1 by Jason Smith
trigger handles on MT
75
  _grab_show_action = 0;
76
  _grab_hide_action = 0;
77
  _grab_toggle_action = 0;
1253 by Neil Jagdish Patel
Use the same default that you provide to compiz
78
  _coverage_area_before_automaximize = 0.75;
1629.1.1 by Jason Smith
make alt-tab able to give priority to windows on the current viewport
79
  bias_active_to_viewport = false;
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
80
}
81
82
PluginAdapter::~PluginAdapter()
83
{
711.1.1 by Jason Smith
Random autohide fixes
84
}
85
729.5.3 by Sam Spilsbury
-> Added maximized window snapoff functionality
86
/* A No-op for now, but could be useful later */
87
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
88
PluginAdapter::OnScreenGrabbed()
729.5.3 by Sam Spilsbury
-> Added maximized window snapoff functionality
89
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
90
  compiz_screen_grabbed.emit();
1014 by Jason Smith
make sure we wait for a grab release when showing places
91
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
92
  if (!_spread_state && screen->grabExist("scale"))
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
93
  {
94
    _spread_state = true;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
95
    initiate_spread.emit();
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
96
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
97
98
  if (!_expo_state && screen->grabExist("expo"))
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
99
  {
100
    _expo_state = true;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
101
    initiate_expo.emit();
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
102
  }
729.5.3 by Sam Spilsbury
-> Added maximized window snapoff functionality
103
}
104
105
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
106
PluginAdapter::OnScreenUngrabbed()
729.5.3 by Sam Spilsbury
-> Added maximized window snapoff functionality
107
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
108
  if (_spread_state && !screen->grabExist("scale"))
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
109
  {
110
    _spread_state = false;
1858.17.56 by Marco Trevisan (Treviño)
PluginAdapter: added IsScaleActiveForGroup to get if scale is running for a window subset
111
    _spread_windows_state = false;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
112
    terminate_spread.emit();
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
113
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
114
115
  if (_expo_state && !screen->grabExist("expo"))
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
116
  {
117
    _expo_state = false;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
118
    terminate_expo.emit();
976.1.4 by Jason Smith
hide/unhide properly with expo/scale
119
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
120
121
  compiz_screen_ungrabbed.emit();
122
}
123
124
void
125
PluginAdapter::NotifyResized(CompWindow* window, int x, int y, int w, int h)
126
{
127
  window_resized.emit(window->id());
128
}
129
130
void
131
PluginAdapter::NotifyMoved(CompWindow* window, int x, int y)
132
{
133
  window_moved.emit(window->id());
134
}
135
136
void
137
PluginAdapter::NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state)
708.1.1 by Jason Smith
add massive signals to plugin adapter
138
{
738.1.2 by Didier Roche
better formatting
139
  if (!((last_state & MAXIMIZE_STATE) == MAXIMIZE_STATE)
140
      && ((state & MAXIMIZE_STATE) == MAXIMIZE_STATE))
669.3.17 by Neil Jagdish Patel
Implement some basic features
141
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
142
    WindowManager::window_maximized.emit(window->id());
669.3.17 by Neil Jagdish Patel
Implement some basic features
143
  }
738.1.2 by Didier Roche
better formatting
144
  else if (((last_state & MAXIMIZE_STATE) == MAXIMIZE_STATE)
145
           && !((state & MAXIMIZE_STATE) == MAXIMIZE_STATE))
669.3.17 by Neil Jagdish Patel
Implement some basic features
146
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
147
    WindowManager::window_restored.emit(window->id());
669.3.17 by Neil Jagdish Patel
Implement some basic features
148
  }
708.1.1 by Jason Smith
add massive signals to plugin adapter
149
}
150
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
151
void
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
152
PluginAdapter::NotifyNewDecorationState(guint32 xid)
153
{
154
  bool wasTracked = (_window_decoration_state.find (xid) != _window_decoration_state.end ());
155
  bool wasDecorated = false;
156
157
  if (wasTracked)
158
    wasDecorated = _window_decoration_state[xid];
159
160
  bool decorated = IsWindowDecorated (xid);
161
162
  if (decorated == wasDecorated)
163
    return;
164
165
  if (decorated && (!wasDecorated || !wasTracked))
166
    WindowManager::window_decorated.emit(xid);
167
  else if (wasDecorated || !wasTracked)
168
    WindowManager::window_undecorated.emit(xid);
169
}
170
171
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
172
PluginAdapter::Notify(CompWindow* window, CompWindowNotify notify)
708.1.1 by Jason Smith
add massive signals to plugin adapter
173
{
174
  switch (notify)
175
  {
176
    case CompWindowNotifyMinimize:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
177
      window_minimized.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
178
      break;
179
    case CompWindowNotifyUnminimize:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
180
      window_unminimized.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
181
      break;
182
    case CompWindowNotifyShade:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
183
      window_shaded.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
184
      break;
185
    case CompWindowNotifyUnshade:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
186
      window_unshaded.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
187
      break;
188
    case CompWindowNotifyHide:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
189
      window_hidden.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
190
      break;
191
    case CompWindowNotifyShow:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
192
      window_shown.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
193
      break;
194
    case CompWindowNotifyMap:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
195
      WindowManager::window_mapped.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
196
      break;
197
    case CompWindowNotifyUnmap:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
198
      WindowManager::window_unmapped.emit(window->id());
708.1.1 by Jason Smith
add massive signals to plugin adapter
199
      break;
1145.1.10 by Didier Roche
Send a signal on focus changed, relying on the mainloop to ensure the new window is the active one (and not the root window) (LP: #734681)
200
    case CompWindowNotifyFocusChange:
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
201
      WindowManager::window_focus_changed.emit(window->id());
1145.1.10 by Didier Roche
Send a signal on focus changed, relying on the mainloop to ensure the new window is the active one (and not the root window) (LP: #734681)
202
      break;
708.1.1 by Jason Smith
add massive signals to plugin adapter
203
    default:
204
      break;
205
  }
206
}
207
208
void
1315.7.1 by Marco Trevisan (Treviño)
PluginAdapter: suport compiz_screen_viewport_switch_{started,ended} signals
209
PluginAdapter::NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option)
210
{
211
  if (g_strcmp0(event, "start_viewport_switch") == 0)
212
  {
213
    _vp_switch_started = true;
214
    compiz_screen_viewport_switch_started.emit();
215
  }
216
  else if (g_strcmp0(event, "end_viewport_switch") == 0)
217
  {
218
    _vp_switch_started = false;
219
    compiz_screen_viewport_switch_ended.emit();
220
  }
1315.7.11 by Marco Trevisan (Treviño)
WindowManager / PluginAdapter add compiz_event signal
221
222
  compiz_event.emit(plugin, event, option);
1315.7.1 by Marco Trevisan (Treviño)
PluginAdapter: suport compiz_screen_viewport_switch_{started,ended} signals
223
}
224
225
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
226
MultiActionList::AddNewAction(CompAction* a, bool primary)
729.5.1 by Sam Spilsbury
Improve spread handling:
227
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
228
  if (std::find(m_ActionList.begin(), m_ActionList.end(), a)  == m_ActionList.end())
229
    m_ActionList.push_back(a);
785.7.1 by Jason Smith
Fix minimize animation
230
231
  if (primary)
232
    _primary_action = a;
729.5.1 by Sam Spilsbury
Improve spread handling:
233
}
234
235
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
236
MultiActionList::RemoveAction(CompAction* a)
729.5.1 by Sam Spilsbury
Improve spread handling:
237
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
238
  m_ActionList.remove(a);
729.5.1 by Sam Spilsbury
Improve spread handling:
239
}
240
241
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
242
MultiActionList::InitiateAll(CompOption::Vector& extraArgs, int state)
729.5.1 by Sam Spilsbury
Improve spread handling:
243
{
244
  CompOption::Vector argument;
2540.9.2 by MC Return
Replaced 'windows.size() > 0' with '!windows.empty()' and '!m_ActionList.size()' with 'm_ActionList.empty()' (x2) in PluginAdapterCompiz.cpp to optimize performance
245
  if (m_ActionList.empty())
729.5.1 by Sam Spilsbury
Improve spread handling:
246
    return;
247
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
248
  argument.resize(1);
249
  argument[0].setName("root", CompOption::TypeInt);
250
  argument[0].value().set((int) screen->root());
251
  foreach(CompOption & arg, extraArgs)
729.5.1 by Sam Spilsbury
Improve spread handling:
252
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
253
    argument.push_back(arg);
729.5.1 by Sam Spilsbury
Improve spread handling:
254
  }
255
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
256
  CompAction* a;
257
785.7.1 by Jason Smith
Fix minimize animation
258
  if (_primary_action)
259
    a = _primary_action;
260
  else
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
261
    a = m_ActionList.front();
262
729.5.1 by Sam Spilsbury
Improve spread handling:
263
  /* Initiate the first available action with the arguments */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
264
  a->initiate()(a, state, argument);
729.5.1 by Sam Spilsbury
Improve spread handling:
265
}
266
267
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
268
MultiActionList::TerminateAll(CompOption::Vector& extraArgs)
729.5.1 by Sam Spilsbury
Improve spread handling:
269
{
270
  CompOption::Vector argument;
271
  CompOption::Value  value;
2540.9.2 by MC Return
Replaced 'windows.size() > 0' with '!windows.empty()' and '!m_ActionList.size()' with 'm_ActionList.empty()' (x2) in PluginAdapterCompiz.cpp to optimize performance
272
  if (m_ActionList.empty())
729.5.1 by Sam Spilsbury
Improve spread handling:
273
    return;
274
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
275
  argument.resize(1);
276
  argument[0].setName("root", CompOption::TypeInt);
277
  argument[0].value().set((int) screen->root());
278
279
  foreach(CompOption & a, extraArgs)
280
  argument.push_back(a);
281
785.7.4 by Jason Smith
make terminate work
282
  if (_primary_action)
283
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
284
    _primary_action->terminate()(_primary_action, 0, argument);
785.7.4 by Jason Smith
make terminate work
285
    return;
286
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
287
288
  foreach(CompAction * action, m_ActionList)
729.5.1 by Sam Spilsbury
Improve spread handling:
289
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
290
    if (action->state() & (CompAction::StateTermKey |
291
                           CompAction::StateTermButton |
292
                           CompAction::StateTermEdge |
293
                           CompAction::StateTermEdgeDnd))
729.5.1 by Sam Spilsbury
Improve spread handling:
294
    {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
295
      action->terminate()(action, 0, argument);
729.5.1 by Sam Spilsbury
Improve spread handling:
296
    }
297
  }
298
}
299
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
300
unsigned long long
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
301
PluginAdapter::GetWindowActiveNumber (guint32 xid) const
1347.1.5 by Jason Smith
more work on alt-tab user interactions
302
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
303
  Window win = xid;
1347.1.5 by Jason Smith
more work on alt-tab user interactions
304
  CompWindow* window;
305
306
  window = m_Screen->findWindow(win);
307
308
  if (window)
309
  {
1629.1.1 by Jason Smith
make alt-tab able to give priority to windows on the current viewport
310
    // result is actually an unsigned int (32 bits)
311
    unsigned long long result = window->activeNum ();
312
    if (bias_active_to_viewport() && window->defaultViewport() == m_Screen->vp())
313
      result = result << 32;
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
314
1629.1.1 by Jason Smith
make alt-tab able to give priority to windows on the current viewport
315
    return result;
1347.1.5 by Jason Smith
more work on alt-tab user interactions
316
  }
317
318
  return 0;
319
}
320
729.5.1 by Sam Spilsbury
Improve spread handling:
321
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
322
PluginAdapter::SetExpoAction(MultiActionList& expo)
729.5.1 by Sam Spilsbury
Improve spread handling:
323
{
324
  m_ExpoActionList = expo;
325
}
326
327
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
328
PluginAdapter::SetScaleAction(MultiActionList& scale)
729.5.1 by Sam Spilsbury
Improve spread handling:
329
{
330
  m_ScaleActionList = scale;
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
331
}
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
332
333
std::string
1456.1.1 by Jason Smith
Implement test launcher stand alone application
334
PluginAdapter::MatchStringForXids(std::vector<Window> *windows)
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
335
{
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
336
  std::ostringstream sout;
337
338
  sout << "any & (";
339
1456.1.1 by Jason Smith
Implement test launcher stand alone application
340
  std::vector<Window>::iterator it;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
341
  for (it = windows->begin(); it != windows->end(); ++it)
729.5.1 by Sam Spilsbury
Improve spread handling:
342
  {
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
343
    sout << "| xid=" << static_cast<int>(*it) << " ";
729.5.1 by Sam Spilsbury
Improve spread handling:
344
  }
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
345
  sout << ")";
346
347
  return sout.str();
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
348
}
1172.1.1 by Tim Penhey
Use std::string by value rather than pointer.
349
350
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
351
PluginAdapter::InitiateScale(std::string const& match, int state)
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
352
{
729.5.1 by Sam Spilsbury
Improve spread handling:
353
  CompOption::Vector argument;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
354
  CompMatch      m(match);
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
355
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
356
  argument.resize(1);
357
  argument[0].setName("match", CompOption::TypeMatch);
358
  argument[0].value().set(m);
729.5.3 by Sam Spilsbury
-> Added maximized window snapoff functionality
359
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
360
  m_ScaleActionList.InitiateAll(argument, state);
361
}
362
363
void
364
PluginAdapter::TerminateScale()
365
{
366
  CompOption::Vector argument(0);
367
  m_ScaleActionList.TerminateAll(argument);
368
}
369
370
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
371
PluginAdapter::IsScaleActive() const
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
372
{
373
  return m_Screen->grabExist("scale");
374
}
375
376
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
377
PluginAdapter::IsScaleActiveForGroup() const
1858.17.56 by Marco Trevisan (Treviño)
PluginAdapter: added IsScaleActiveForGroup to get if scale is running for a window subset
378
{
379
  return _spread_windows_state && m_Screen->grabExist("scale");
380
}
381
382
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
383
PluginAdapter::IsExpoActive() const
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
384
{
385
  return m_Screen->grabExist("expo");
386
}
387
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
388
bool
389
PluginAdapter::IsWallActive() const
390
{
391
  return m_Screen->grabExist("wall");
392
}
393
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
394
void
395
PluginAdapter::InitiateExpo()
396
{
397
  CompOption::Vector argument(0);
398
399
  m_ExpoActionList.InitiateAll(argument, 0);
572.1.11 by Neil Jagdish Patel
Import the work done so far with Compiz
400
}
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
401
402
// WindowManager implementation
1776.4.34 by Marco Trevisan (Treviño)
WindowManager: add method to get the active window.
403
guint32
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
404
PluginAdapter::GetActiveWindow() const
1776.4.34 by Marco Trevisan (Treviño)
WindowManager: add method to get the active window.
405
{
406
  return m_Screen->activeWindow();
407
}
408
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
409
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
410
PluginAdapter::IsWindowMaximized(guint xid) const
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
411
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
412
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
413
  CompWindow* window;
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
414
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
415
  window = m_Screen->findWindow(win);
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
416
  if (window)
417
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
418
    return ((window->state() & MAXIMIZE_STATE) == MAXIMIZE_STATE);
669.3.13 by Neil Jagdish Patel
Show something, but input events are broken
419
  }
420
421
  return false;
422
}
669.3.15 by Neil Jagdish Patel
hook up some signals
423
669.3.21 by Neil Jagdish Patel
Support for knowing the state of window decorations
424
bool
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
425
PluginAdapter::IsWindowDecorated(guint32 xid)
669.3.21 by Neil Jagdish Patel
Support for knowing the state of window decorations
426
{
1468.1.22 by Marco Trevisan (Treviño)
Fixing for good the Redecorate maximized windows issue.
427
  Display* display = m_Screen->dpy();
428
  Window win = xid;
429
  Atom hints_atom = None;
430
  MotifWmHints* hints = NULL;
431
  Atom type = None;
432
  gint format;
433
  gulong nitems;
434
  gulong bytes_after;
435
  bool ret = true;
436
437
  hints_atom = XInternAtom(display, _XA_MOTIF_WM_HINTS, false);
438
1641.1.1 by Robert Carr
Always check the return value of XGetWindowProperty
439
  if (XGetWindowProperty(display, win, hints_atom, 0,
440
                         sizeof(MotifWmHints) / sizeof(long), False,
441
                         hints_atom, &type, &format, &nitems, &bytes_after,
442
                         (guchar**)&hints) != Success)
443
    return false;
1468.1.22 by Marco Trevisan (Treviño)
Fixing for good the Redecorate maximized windows issue.
444
445
  if (!hints)
446
    return ret;
447
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
448
  /* Check for the presence of the high bit
449
   * if present, it means that we undecorated
450
   * this window, so don't mark it as undecorated */
451
  if (type == hints_atom && format != 0 &&
452
      hints->flags & MWM_HINTS_DECORATIONS)
1468.1.22 by Marco Trevisan (Treviño)
Fixing for good the Redecorate maximized windows issue.
453
  {
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
454
    /* Must have both bits set */
455
    _window_decoration_state[xid] = ret =
456
          (hints->decorations & (MwmDecorAll | MwmDecorTitle))  ||
457
          (hints->decorations & MWM_HINTS_UNDECORATED_UNITY);
1468.1.22 by Marco Trevisan (Treviño)
Fixing for good the Redecorate maximized windows issue.
458
  }
459
460
  XFree(hints);
461
  return ret;
669.3.21 by Neil Jagdish Patel
Support for knowing the state of window decorations
462
}
463
950.2.1 by Dylan McCall
MouseDown in menu bar drag area affects last maximized window, regardless of current focus (LP: 716177).
464
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
465
PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
466
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
467
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
468
  CompWindow* window;
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
469
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
470
  window = m_Screen->findWindow(win);
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
471
  if (window)
472
  {
950.2.6 by Dylan McCall
Removed code that compares window->desktop (), because that cannot be trusted.
473
    // we aren't checking window->onCurrentDesktop (), as the name implies, because that is broken
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
474
    return (window->defaultViewport() == m_Screen->vp());
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
475
  }
476
477
  return false;
478
}
479
480
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
481
PluginAdapter::IsWindowObscured(guint32 xid) const
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
482
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
483
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
484
  CompWindow* window;
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
485
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
486
  window = m_Screen->findWindow(win);
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
487
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
488
  if (window)
489
  {
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
490
    if (window->inShowDesktopMode())
491
      return true;
492
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
493
    CompPoint window_vp = window->defaultViewport();
1858.17.46 by Marco Trevisan (Treviño)
PluginAdapter: window's can't be obscured by window in different screens.
494
    nux::Geometry const& win_geo = GetWindowGeometry(window->id());
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
495
    // Check if any windows above this one are blocking it
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
496
    for (CompWindow* sibling = window->next; sibling != NULL; sibling = sibling->next)
950.2.2 by Dylan McCall
IsWindowVisible checks for maximized windows above the given window, on the current desktop and viewport. Fixes ordering issue from last commit.
497
    {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
498
      if (sibling->defaultViewport() == window_vp
499
          && !sibling->minimized()
1468.1.16 by Marco Trevisan (Treviño)
Don't consider unmapped and unviewable windows in IsWindowObscured
500
          && sibling->isMapped()
501
          && sibling->isViewable()
1858.17.46 by Marco Trevisan (Treviño)
PluginAdapter: window's can't be obscured by window in different screens.
502
          && (sibling->state() & MAXIMIZE_STATE) == MAXIMIZE_STATE
503
          && !GetWindowGeometry(sibling->id()).Intersect(win_geo).IsNull())
504
      {
950.2.3 by Dylan McCall
Strengthened code for determining front-most maximized window.
505
        return true;
1858.17.46 by Marco Trevisan (Treviño)
PluginAdapter: window's can't be obscured by window in different screens.
506
      }
950.2.2 by Dylan McCall
IsWindowVisible checks for maximized windows above the given window, on the current desktop and viewport. Fixes ordering issue from last commit.
507
    }
950.2.1 by Dylan McCall
MouseDown in menu bar drag area affects last maximized window, regardless of current focus (LP: 716177).
508
  }
509
510
  return false;
511
}
512
1576.1.1 by Sam Spilsbury
Fix LP#732997 - do not override minimization functions until the window
513
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
514
PluginAdapter::IsWindowMapped(guint32 xid) const
1576.1.1 by Sam Spilsbury
Fix LP#732997 - do not override minimization functions until the window
515
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
516
  Window win = xid;
1576.1.1 by Sam Spilsbury
Fix LP#732997 - do not override minimization functions until the window
517
  CompWindow* window;
518
519
  window = m_Screen->findWindow(win);
520
  if (window)
521
    return window->mapNum () > 0;
522
  return true;
523
}
524
1719.1.2 by Sam Spilsbury
Always unminimize the windows on the current workspace if none of the windows
525
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
526
PluginAdapter::IsWindowVisible(guint32 xid) const
1719.1.2 by Sam Spilsbury
Always unminimize the windows on the current workspace if none of the windows
527
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
528
  Window win = xid;
1719.1.2 by Sam Spilsbury
Always unminimize the windows on the current workspace if none of the windows
529
  CompWindow* window;
530
531
  window = m_Screen->findWindow(win);
532
  if (window)
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
533
    return !(window->state() & CompWindowStateHiddenMask) && !window->inShowDesktopMode();
534
535
  return false;
536
}
537
538
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
539
PluginAdapter::IsWindowOnTop(guint32 xid) const
2324.3.1 by Marco Trevisan (Treviño)
WindowManager: add method to get if a window is on top.
540
{
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
541
  if (xid == GetTopMostValidWindowInViewport())
542
    return true;
2692.2.3 by Brandon Schaefer
* Remove redundant code
543
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
544
  return false;
545
}
546
547
Window PluginAdapter::GetTopMostValidWindowInViewport() const
548
{
549
  CompWindow* window;
550
  CompPoint screen_vp = m_Screen->vp();
2692.2.5 by Brandon Schaefer
* Check that the window is owned by nux.
551
  std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
552
2692.2.4 by Brandon Schaefer
* small change
553
  auto const& windows = m_Screen->windows();
554
  for (auto it = windows.rbegin(); it != windows.rend(); ++it)
2324.3.1 by Marco Trevisan (Treviño)
WindowManager: add method to get if a window is on top.
555
  {
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
556
    window = *it;
557
    if (window->defaultViewport() == screen_vp &&
558
        window->isViewable() && window->isMapped() &&
559
        !window->minimized() && !window->inShowDesktopMode() &&
560
        !(window->state() & CompWindowStateAboveMask) &&
561
        !(window->type() & CompWindowTypeSplashMask) &&
562
        !(window->type() & CompWindowTypeDockMask) &&
2692.2.5 by Brandon Schaefer
* Check that the window is owned by nux.
563
        !window->overrideRedirect() &&
2745.1.1 by Marco Trevisan (Treviño)
PluginAdapterCompiz: correctly use std::find to look in our xids list
564
        std::find(our_xids.begin(), our_xids.end(), window->id()) == our_xids.end())
2692.2.3 by Brandon Schaefer
* Remove redundant code
565
    {
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
566
      return window->id();
2692.2.3 by Brandon Schaefer
* Remove redundant code
567
    }
2324.3.1 by Marco Trevisan (Treviño)
WindowManager: add method to get if a window is on top.
568
  }
2692.2.1 by Brandon Schaefer
* Ignore windows that have override redirect set to true, in IsWindowOnTop
569
  return 0;
2324.3.1 by Marco Trevisan (Treviño)
WindowManager: add method to get if a window is on top.
570
}
571
572
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
573
PluginAdapter::IsWindowClosable(guint32 xid) const
2280.3.1 by Marco Trevisan (Treviño)
WindowManager: add functions to get if a window is maximizable and closable
574
{
575
  Window win = xid;
576
  CompWindow* window;
577
578
  window = m_Screen->findWindow(win);
579
  if (window)
580
    return (window->actions() & CompWindowActionCloseMask);
581
582
  return false;
583
}
584
585
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
586
PluginAdapter::IsWindowMinimizable(guint32 xid) const
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
587
{
588
  Window win = xid;
589
  CompWindow* window;
590
591
  window = m_Screen->findWindow(win);
592
  if (window)
593
    return (window->actions() & CompWindowActionMinimizeMask);
594
595
  return false;
1858.9.145 by Marco Trevisan (Treviño)
WindowManager: add getter to check if a window is minimizable.
596
}
597
2280.3.1 by Marco Trevisan (Treviño)
WindowManager: add functions to get if a window is maximizable and closable
598
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
599
PluginAdapter::IsWindowMaximizable(guint32 xid) const
2280.3.1 by Marco Trevisan (Treviño)
WindowManager: add functions to get if a window is maximizable and closable
600
{
601
  Window win = xid;
602
  CompWindow* window;
603
604
  window = m_Screen->findWindow(win);
605
  if (window)
606
    return (window->actions() & MAXIMIZABLE);
607
608
  return false;
609
}
610
669.3.15 by Neil Jagdish Patel
hook up some signals
611
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
612
PluginAdapter::Restore(guint32 xid)
613
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
614
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
615
  CompWindow* window;
616
617
  window = m_Screen->findWindow(win);
618
  if (window)
619
    window->maximize(0);
620
}
621
622
void
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
623
PluginAdapter::RestoreAt(guint32 xid, int x, int y)
624
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
625
  Window win = xid;
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
626
  CompWindow* window;
627
628
  window = m_Screen->findWindow(win);
629
  if (window && (window->state() & MAXIMIZE_STATE))
630
  {
631
    nux::Geometry new_geo(GetWindowSavedGeometry(xid));
632
    new_geo.x = x;
633
    new_geo.y = y;
634
    window->maximize(0);
635
    MoveResizeWindow(xid, new_geo);
636
  }
637
}
638
639
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
640
PluginAdapter::Minimize(guint32 xid)
641
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
642
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
643
  CompWindow* window;
644
645
  window = m_Screen->findWindow(win);
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
646
  if (window && (window->actions() & CompWindowActionMinimizeMask))
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
647
    window->minimize();
648
}
649
650
void
651
PluginAdapter::Close(guint32 xid)
652
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
653
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
654
  CompWindow* window;
655
656
  window = m_Screen->findWindow(win);
657
  if (window)
658
    window->close(CurrentTime);
659
}
660
661
void
662
PluginAdapter::Activate(guint32 xid)
663
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
664
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
665
  CompWindow* window;
666
667
  window = m_Screen->findWindow(win);
668
  if (window)
669
    window->activate();
670
}
671
672
void
673
PluginAdapter::Raise(guint32 xid)
674
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
675
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
676
  CompWindow* window;
677
678
  window = m_Screen->findWindow(win);
679
  if (window)
680
    window->raise();
681
}
682
683
void
684
PluginAdapter::Lower(guint32 xid)
685
{
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
686
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
687
  CompWindow* window;
688
689
  window = m_Screen->findWindow(win);
690
  if (window)
691
    window->lower();
692
}
693
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
694
void
1776.4.38 by Marco Trevisan (Treviño)
WindowManager, BamfLauncherIcon: some code cleanup
695
PluginAdapter::FocusWindowGroup(std::vector<Window> window_ids, FocusVisibility focus_visibility, int monitor, bool only_top_win)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
696
{
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
697
  CompPoint target_vp = m_Screen->vp();
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
698
  CompWindow* top_window = nullptr;
699
  CompWindow* top_monitor_win = nullptr;
700
1456.1.1 by Jason Smith
Implement test launcher stand alone application
701
  bool any_on_current = false;
702
  bool any_mapped = false;
2004.5.1 by Jason Smith
fix issue where windows wouldn't unminimize with alt-tab
703
  bool any_mapped_on_current = false;
1719.1.4 by Sam Spilsbury
Remove debug message and fix focusing across desktops
704
  bool forced_unminimize = false;
1456.1.1 by Jason Smith
Implement test launcher stand alone application
705
706
  /* sort the list */
707
  CompWindowList windows;
708
  for (auto win : m_Screen->clientList())
709
  {
710
    Window id = win->id();
711
    if (std::find(window_ids.begin(), window_ids.end(), id) != window_ids.end())
712
      windows.push_back(win);
713
  }
714
715
  /* filter based on workspace */
716
  for (CompWindow* &win : windows)
717
  {
718
    if (win->defaultViewport() == m_Screen->vp())
719
    {
720
      any_on_current = true;
2004.5.1 by Jason Smith
fix issue where windows wouldn't unminimize with alt-tab
721
722
      if (!win->minimized())
723
      {
724
        any_mapped_on_current = true;
725
      }
1456.1.1 by Jason Smith
Implement test launcher stand alone application
726
    }
727
728
    if (!win->minimized())
729
    {
730
      any_mapped = true;
731
    }
732
733
    if (any_on_current && any_mapped)
734
      break;
735
  }
736
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
737
  if (!any_on_current)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
738
  {
1776.4.3 by Marco Trevisan (Treviño)
PluginAdapter: Add support for the FocusVisibility::OnlyVisibleOnTop on FocusWindowGroup
739
    for (auto it = windows.rbegin(); it != windows.rend(); ++it)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
740
    {
1776.4.3 by Marco Trevisan (Treviño)
PluginAdapter: Add support for the FocusVisibility::OnlyVisibleOnTop on FocusWindowGroup
741
      CompWindow* win = *it;
742
      if ((any_mapped && !win->minimized()) || !any_mapped)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
743
      {
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
744
        target_vp = win->defaultViewport();
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
745
        break;
1456.1.1 by Jason Smith
Implement test launcher stand alone application
746
      }
747
    }
748
  }
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
749
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
750
  for (CompWindow* &win : windows)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
751
  {
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
752
    if (win->defaultViewport() == target_vp)
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
753
    {
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
754
      int win_monitor = GetWindowMonitor(win->id());
755
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
756
      /* Any window which is actually unmapped is
757
      * not going to be accessible by either switcher
758
      * or scale, so unconditionally unminimize those
759
      * windows when the launcher icon is activated */
760
      if ((focus_visibility == WindowManager::FocusVisibility::ForceUnminimizeOnCurrentDesktop &&
761
          target_vp == m_Screen->vp()) ||
762
          (focus_visibility == WindowManager::FocusVisibility::ForceUnminimizeInvisible &&
763
           win->mapNum() == 0))
1776.4.3 by Marco Trevisan (Treviño)
PluginAdapter: Add support for the FocusVisibility::OnlyVisibleOnTop on FocusWindowGroup
764
      {
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
765
        top_window = win;
766
        forced_unminimize = true;
767
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
768
        if (monitor >= 0 && win_monitor == monitor)
769
          top_monitor_win = win;
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
770
771
        if (!only_top_win)
1776.4.7 by Brandon Schaefer
* Fixed tabbing issues
772
        {
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
773
          bool is_mapped = (win->mapNum() != 0);
774
          win->unminimize();
1776.4.7 by Brandon Schaefer
* Fixed tabbing issues
775
776
           /* Initially minimized windows dont get raised */
777
          if (!is_mapped)
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
778
            win->raise();
1776.4.7 by Brandon Schaefer
* Fixed tabbing issues
779
        }
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
780
      }
781
      else if ((any_mapped_on_current && !win->minimized()) || !any_mapped_on_current)
782
      {
783
        if (!forced_unminimize || target_vp == m_Screen->vp())
1776.4.7 by Brandon Schaefer
* Fixed tabbing issues
784
        {
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
785
          top_window = win;
786
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
787
          if (monitor >= 0 && win_monitor == monitor)
788
            top_monitor_win = win;
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
789
790
          if (!only_top_win)
1776.4.7 by Brandon Schaefer
* Fixed tabbing issues
791
            win->raise();
1776.4.3 by Marco Trevisan (Treviño)
PluginAdapter: Add support for the FocusVisibility::OnlyVisibleOnTop on FocusWindowGroup
792
        }
793
      }
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
794
    }
1456.1.1 by Jason Smith
Implement test launcher stand alone application
795
  }
1658.1.2 by Marco Trevisan (Treviño)
PluginAdapter: correctly map the windows in other viewports
796
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
797
  if (monitor >= 0 && top_monitor_win)
798
    top_window = top_monitor_win;
1776.4.21 by Marco Trevisan (Treviño)
PluginAdapter::FocusWindowGroup: add a parameter to define if focusing the on-top window only
799
800
  if (top_window)
1858.17.33 by Marco Trevisan (Treviño)
PluginAdapter: add some more spacing, to improve readability
801
  {
1776.4.41 by Marco Trevisan (Treviño)
PluginAdapter: avoid to raise and unminimize top_window if already done
802
    if (only_top_win)
803
    {
804
      if (forced_unminimize)
805
        {
806
          top_window->unminimize();
807
        }
808
809
      top_window->raise();
810
    }
811
1820.1.31 by Jason Smith
monitor aware focus behavior
812
    top_window->activate();
1858.17.33 by Marco Trevisan (Treviño)
PluginAdapter: add some more spacing, to improve readability
813
  }
1456.1.1 by Jason Smith
Implement test launcher stand alone application
814
}
815
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
816
bool
1456.1.1 by Jason Smith
Implement test launcher stand alone application
817
PluginAdapter::ScaleWindowGroup(std::vector<Window> windows, int state, bool force)
818
{
2540.9.7 by MC Return
Introduced std::size_t num_windows = windows.size(); and changed the if statement in PluginAdapter::ScaleWindowGroup to check num_windows
819
  std::size_t num_windows = windows.size();
820
  if (num_windows > 1 || (force && num_windows))
1456.1.1 by Jason Smith
Implement test launcher stand alone application
821
  {
822
    std::string match = MatchStringForXids(&windows);
823
    InitiateScale(match, state);
1858.17.56 by Marco Trevisan (Treviño)
PluginAdapter: added IsScaleActiveForGroup to get if scale is running for a window subset
824
    _spread_windows_state = true;
1456.1.1 by Jason Smith
Implement test launcher stand alone application
825
    return true;
826
  }
827
  return false;
828
}
829
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
830
void
1456.1.1 by Jason Smith
Implement test launcher stand alone application
831
PluginAdapter::SetWindowIconGeometry(Window window, nux::Geometry const& geo)
832
{
833
  long data[4];
834
835
  data[0] = geo.x;
836
  data[1] = geo.y;
837
  data[2] = geo.width;
838
  data[3] = geo.height;
839
840
  XChangeProperty(m_Screen->dpy(), window, Atoms::wmIconGeometry,
841
                  XA_CARDINAL, 32, PropModeReplace,
842
                  (unsigned char*) data, 4);
843
}
844
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
845
void
846
PluginAdapter::ShowDesktop()
847
{
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
848
  if (_in_show_desktop)
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
849
  {
850
    LOG_INFO(logger) << "Leaving show-desktop mode.";
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
851
    m_Screen->leaveShowDesktopMode(NULL);
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
852
  }
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
853
  else
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
854
  {
855
    LOG_INFO(logger) << "Entering show-desktop mode.";
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
856
    m_Screen->enterShowDesktopMode();
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
857
  }
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
858
}
859
2529.14.74 by Marco Trevisan (Treviño)
WindowManager: add InShowDesktop (and implement it in PluginAdapter's).
860
bool PluginAdapter::InShowDesktop() const
861
{
862
  return _in_show_desktop;
863
}
864
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
865
void
866
PluginAdapter::OnShowDesktop()
867
{
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
868
  LOG_DEBUG(logger) << "Now in show desktop mode.";
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
869
  _in_show_desktop = true;
870
}
871
872
void
873
PluginAdapter::OnLeaveDesktop()
874
{
2424.2.2 by Thomi Richards
Make log messages easier to tell apart.
875
  LOG_DEBUG(logger) << "No longer in show desktop mode.";
1410.5.18 by Sam Spilsbury
Merge trunk and add a rudimentary showdesktop functionality so that
876
  _in_show_desktop = false;
1286.1.1 by Jason Smith
implement fixes and changes to alt tab as requested by design
877
}
878
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
879
int
880
PluginAdapter::GetWindowMonitor(guint32 xid) const
881
{
1776.4.26 by Marco Trevisan (Treviño)
Launcher: if the current launcher is used for all the monitors, don't filter windows per monitor
882
  // FIXME, we should use window->outputDevice() but this is not UScreen friendly
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
883
  nux::Geometry const& geo = GetWindowGeometry(xid);
884
885
  if (!geo.IsNull())
886
  {
887
    int x = geo.x + geo.width/2;
888
    int y = geo.y + geo.height/2;
889
2290.1.3 by Marco Trevisan (Treviño)
UScreen: code updated to be more C++ friendly.
890
    return unity::UScreen::GetDefault()->GetMonitorAtPosition(x, y);
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
891
  }
892
893
  return -1;
894
}
895
989.1.3 by Neil Jagdish Patel
Don't show BFB on \!primary monitors as it causes broken interations with the dash/launcher
896
nux::Geometry
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
897
PluginAdapter::GetWindowGeometry(guint32 xid) const
989.1.3 by Neil Jagdish Patel
Don't show BFB on \!primary monitors as it causes broken interations with the dash/launcher
898
{
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
899
  Window win = xid;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
900
  CompWindow* window;
1776.4.24 by Marco Trevisan (Treviño)
WindowManager: add GetWindowMonitor method, and use UScreen to fetch it
901
  nux::Geometry geo;
989.1.3 by Neil Jagdish Patel
Don't show BFB on \!primary monitors as it causes broken interations with the dash/launcher
902
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
903
  window = m_Screen->findWindow(win);
989.1.3 by Neil Jagdish Patel
Don't show BFB on \!primary monitors as it causes broken interations with the dash/launcher
904
  if (window)
905
  {
1529.1.4 by Jason Smith
fix merge issues
906
    geo.x = window->borderRect().x();
907
    geo.y = window->borderRect().y();
908
    geo.width = window->borderRect().width();
909
    geo.height = window->borderRect().height();
989.1.3 by Neil Jagdish Patel
Don't show BFB on \!primary monitors as it causes broken interations with the dash/launcher
910
  }
911
  return geo;
912
}
913
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
914
nux::Geometry
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
915
PluginAdapter::GetWindowSavedGeometry(guint32 xid) const
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
916
{
917
  Window win = xid;
918
  nux::Geometry geo(0, 0, 1, 1);
919
  CompWindow* window;
920
921
  window = m_Screen->findWindow(win);
922
  if (window)
923
  {
924
    XWindowChanges &wc = window->saveWc();
925
    geo.x = wc.x;
926
    geo.y = wc.y;
927
    geo.width = wc.width;
928
    geo.height = wc.height;
929
  }
930
931
  return geo;
932
}
933
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
934
nux::Geometry
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
935
PluginAdapter::GetScreenGeometry() const
1456.1.1 by Jason Smith
Implement test launcher stand alone application
936
{
937
  nux::Geometry geo;
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
938
1456.1.1 by Jason Smith
Implement test launcher stand alone application
939
  geo.x = 0;
940
  geo.y = 0;
941
  geo.width = m_Screen->width();
942
  geo.height = m_Screen->height();
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
943
944
  return geo;
1456.1.1 by Jason Smith
Implement test launcher stand alone application
945
}
946
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
947
nux::Geometry
2194.9.5 by Marco Trevisan (Treviño)
WindowManager: GetGeometry* related methods set to const
948
PluginAdapter::GetWorkAreaGeometry(guint32 xid) const
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
949
{
950
  CompWindow* window = nullptr;
951
  unsigned int output = 0;
952
953
  if (xid != 0)
954
  {
955
    Window win = xid;
956
957
    window = m_Screen->findWindow(win);
958
    if (window)
959
    {
960
      output = window->outputDevice();
961
    }
962
  }
963
964
  if (xid == 0 || !window)
965
  {
966
    output = m_Screen->currentOutputDev().id();
967
  }
968
969
  CompRect workarea = m_Screen->getWorkareaForOutput(output);
970
971
  return nux::Geometry(workarea.x(), workarea.y(), workarea.width(), workarea.height());
972
}
973
1456.1.1 by Jason Smith
Implement test launcher stand alone application
974
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
975
PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const
1456.1.1 by Jason Smith
Implement test launcher stand alone application
976
{
977
  int intersect_types = CompWindowTypeNormalMask | CompWindowTypeDialogMask |
978
                        CompWindowTypeModalDialogMask | CompWindowTypeUtilMask;
979
1692.3.1 by Sam Spilsbury
Check for hidden windows rather than minimized ones to cover the
980
  if (!window ||
981
      !(window->type() & intersect_types) ||
982
      !window->isMapped() ||
983
      !window->isViewable() ||
1692.3.2 by Sam Spilsbury
Fix space
984
      window->state() & CompWindowStateHiddenMask)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
985
    return false;
986
987
  if (CompRegion(window->borderRect()).intersects(CompRect(region.x, region.y, region.width, region.height)))
988
    return true;
989
990
  return false;
991
}
992
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
993
void
1456.1.1 by Jason Smith
Implement test launcher stand alone application
994
PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any)
995
{
996
  // prime to false so we can assume values later one
997
  active = false;
998
  any = false;
999
1000
  CompWindowList window_list = m_Screen->windows();
1001
  CompWindowList::iterator it;
1002
  CompWindow* window = NULL;
1003
  CompWindow* parent = NULL;
1004
  int type_dialogs = CompWindowTypeDialogMask | CompWindowTypeModalDialogMask
1005
                     | CompWindowTypeUtilMask;
1006
1007
1008
  window = m_Screen->findWindow(m_Screen->activeWindow());
1009
1010
  if (window && (window->type() & type_dialogs))
1011
    parent = m_Screen->findWindow(window->transientFor());
1012
1013
  if (CheckWindowIntersection(region, window) || CheckWindowIntersection(region, parent))
1014
  {
1015
    any = true;
1016
    active = true;
1017
  }
1018
  else
1019
  {
2528.1.14 by MC Return
Fixed possible performance issue in PluginAdapterCompiz.cpp by replacement of postfix ++ operator with prefix one
1020
    for (it = window_list.begin(); it != window_list.end(); ++it)
1456.1.1 by Jason Smith
Implement test launcher stand alone application
1021
    {
1022
      if (CheckWindowIntersection(region, *it))
1023
      {
1024
        any = true;
1025
        break;
1026
      }
1027
    }
1028
  }
1029
}
1030
1031
int
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
1032
PluginAdapter::WorkspaceCount() const
1456.1.1 by Jason Smith
Implement test launcher stand alone application
1033
{
1034
  return m_Screen->vpSize().width() * m_Screen->vpSize().height();
1035
}
1036
1091 by Jason Smith
decorate/undecorate using compiz display
1037
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1038
PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints)
1091 by Jason Smith
decorate/undecorate using compiz display
1039
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1040
  Display* display = m_Screen->dpy();
1091 by Jason Smith
decorate/undecorate using compiz display
1041
  Atom hints_atom = None;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1042
  MotifWmHints* data = NULL;
1043
  MotifWmHints* hints = NULL;
1091 by Jason Smith
decorate/undecorate using compiz display
1044
  Atom type = None;
1045
  gint format;
1046
  gulong nitems;
1047
  gulong bytes_after;
1048
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1049
  hints_atom = XInternAtom(display, _XA_MOTIF_WM_HINTS, false);
1050
1712 by Robert Carr
Always check return value of XGetWindowProperty otherwise we sometimes free a random chunk of memory
1051
  if (XGetWindowProperty(display,
1052
                         xid,
1053
                         hints_atom, 0, sizeof(MotifWmHints) / sizeof(long),
1054
                         False, AnyPropertyType, &type, &format, &nitems,
1055
                         &bytes_after, (guchar**)&data) != Success)
1056
  {
1057
    return;
1058
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1059
1091 by Jason Smith
decorate/undecorate using compiz display
1060
  if (type != hints_atom || !data)
1061
  {
1062
    hints = new_hints;
1063
  }
1064
  else
1065
  {
1066
    hints = data;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1067
1091 by Jason Smith
decorate/undecorate using compiz display
1068
    if (new_hints->flags & MWM_HINTS_FUNCTIONS)
1069
    {
1070
      hints->flags |= MWM_HINTS_FUNCTIONS;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1071
      hints->functions = new_hints->functions;
1091 by Jason Smith
decorate/undecorate using compiz display
1072
    }
1073
    if (new_hints->flags & MWM_HINTS_DECORATIONS)
1074
    {
1075
      hints->flags |= MWM_HINTS_DECORATIONS;
1076
      hints->decorations = new_hints->decorations;
1077
    }
1078
  }
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1079
1080
  XChangeProperty(display,
1081
                  xid,
1082
                  hints_atom, hints_atom, 32, PropModeReplace,
1083
                  (guchar*)hints, sizeof(MotifWmHints) / sizeof(long));
1084
1091 by Jason Smith
decorate/undecorate using compiz display
1085
  if (data)
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1086
    XFree(data);
1091 by Jason Smith
decorate/undecorate using compiz display
1087
}
1088
1089
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1090
PluginAdapter::Decorate(guint32 xid)
1091 by Jason Smith
decorate/undecorate using compiz display
1091
{
1092
  MotifWmHints hints = { 0 };
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1093
1091 by Jason Smith
decorate/undecorate using compiz display
1094
  hints.flags = MWM_HINTS_DECORATIONS;
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1095
  hints.decorations = GDK_DECOR_ALL & ~(MWM_HINTS_UNDECORATED_UNITY);
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1096
1097
  SetMwmWindowHints(xid, &hints);
1091 by Jason Smith
decorate/undecorate using compiz display
1098
}
1099
1100
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1101
PluginAdapter::Undecorate(guint32 xid)
1091 by Jason Smith
decorate/undecorate using compiz display
1102
{
1103
  MotifWmHints hints = { 0 };
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1104
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1105
  /* Set the high bit to indicate that we undecorated this
1106
   * window, when an application attempts to "undecorate"
1107
   * the window again, this bit will be cleared */
1091 by Jason Smith
decorate/undecorate using compiz display
1108
  hints.flags = MWM_HINTS_DECORATIONS;
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1109
  hints.decorations = MWM_HINTS_UNDECORATED_UNITY;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1110
1111
  SetMwmWindowHints(xid, &hints);
1091 by Jason Smith
decorate/undecorate using compiz display
1112
}
1113
1014 by Jason Smith
make sure we wait for a grab release when showing places
1114
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
1115
PluginAdapter::IsScreenGrabbed() const
1014 by Jason Smith
make sure we wait for a grab release when showing places
1116
{
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1117
  return m_Screen->grabbed();
1014 by Jason Smith
make sure we wait for a grab release when showing places
1118
}
1119
1315.7.1 by Marco Trevisan (Treviño)
PluginAdapter: suport compiz_screen_viewport_switch_{started,ended} signals
1120
bool
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
1121
PluginAdapter::IsViewPortSwitchStarted() const
1315.7.1 by Marco Trevisan (Treviño)
PluginAdapter: suport compiz_screen_viewport_switch_{started,ended} signals
1122
{
1123
  return _vp_switch_started;
1124
}
1125
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1126
/* Returns true if the window was maximized */
2529.8.1 by Brandon Schaefer
* Switcher is disabled now when the Wall plugin is active.
1127
bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) const
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1128
{
1129
  XClassHint   classHint;
1130
  Status       status;
1178.2.1 by Cameron Hart
Check window's maximum size before attepmpting to maximize. Also fix memory leak by using a std:string instead of a strdup char* which is not freed on all code paths.
1131
  std::string  win_wmclass;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1132
  int          num_monitor;
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1133
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1134
  int          screen_width;
1135
  int          screen_height;
740.1.6 by Didier Roche
use coverage area rather than comparing value and remove blacklist
1136
  float        covering_part;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1137
1138
  if (!window)
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1139
    return false;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1140
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1141
  if ((window->state() & MAXIMIZE_STATE) == MAXIMIZE_STATE)
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1142
    return false;
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1143
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1144
  if (window->type() != CompWindowTypeNormalMask
1145
      || (window->actions() & MAXIMIZABLE) != MAXIMIZABLE)
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1146
    return false;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1147
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1148
  status = XGetClassHint(m_Screen->dpy(), window->id(), &classHint);
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1149
  if (status && classHint.res_class)
1150
  {
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1151
    win_wmclass = classHint.res_class;
1152
    XFree(classHint.res_class);
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
1153
1323.3.2 by Andrea Azzarone
Fix memory leak in PluginAdapter.cpp (bug #818477)
1154
    if (classHint.res_name)
1155
      XFree(classHint.res_name);
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1156
  }
1157
  else
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1158
    return false;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1159
1160
  num_monitor = window->outputDevice();
1672.1.1 by Sam Spilsbury
Maybe fix LP#861143
1161
  CompOutput &o = m_Screen->outputDevs().at(num_monitor);
1162
1163
  screen_height = o.workArea().height();
1164
  screen_width = o.workArea().width();
2424.2.1 by Thomi Richards
Added logging to the unity/compiz plugin class, and set all tests to attach those logs to failed AP tests.
1165
1818.5.2 by Andrea Azzarone
Fixes.
1166
  // See bug https://bugs.launchpad.net/unity/+bug/797808
1167
  if (screen_height * screen_width > THRESHOLD_HEIGHT * THRESHOLD_WIDTH)
1818.5.1 by Andrea Azzarone
Disables window auto-maximise functionality if the monitor resolution is greater then 1024x600.
1168
    return false;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1169
1170
  // use server<parameter> because the window won't show the real parameter as
1171
  // not mapped yet
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1172
  const XSizeHints& hints = window->sizeHints();
1173
  covering_part = (float)(window->serverWidth() * window->serverHeight()) / (float)(screen_width * screen_height);
1195.5.1 by Marco Biscaro
Creating option to adjust the automaximize value (LP: #754214).
1174
  if ((covering_part < _coverage_area_before_automaximize) || (covering_part > 1.0) ||
1178.2.1 by Cameron Hart
Check window's maximum size before attepmpting to maximize. Also fix memory leak by using a std:string instead of a strdup char* which is not freed on all code paths.
1175
      (hints.flags & PMaxSize && (screen_width > hints.max_width || screen_height > hints.max_height)))
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1176
  {
1224.3.5 by Tim Penhey
Use the new logger.
1177
    LOG_DEBUG(logger) << win_wmclass << " window size doesn't fit";
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1178
    return false;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1179
  }
1180
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1181
  window->maximize(MAXIMIZE_STATE);
1692.4.1 by Sam Spilsbury
Do automaximization on placement which only happens once when the window
1182
1183
  return true;
740.1.4 by Didier Roche
Automaximize windows in Unity with some rules like blacklisting some
1184
}
1011.1.1 by Jason Smith
trigger handles on MT
1185
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1186
void
1187
PluginAdapter::ShowGrabHandles(CompWindow* window, bool use_timer)
1011.1.1 by Jason Smith
trigger handles on MT
1188
{
1067 by Jason Smith
some extra crash protection
1189
  if (!_grab_show_action || !window)
1011.1.1 by Jason Smith
trigger handles on MT
1190
    return;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1191
1011.1.1 by Jason Smith
trigger handles on MT
1192
  CompOption::Vector argument;
1193
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1194
  argument.resize(3);
1195
  argument[0].setName("root", CompOption::TypeInt);
1196
  argument[0].value().set((int) screen->root());
1197
  argument[1].setName("window", CompOption::TypeInt);
1198
  argument[1].value().set((int) window->id());
1199
  argument[2].setName("use-timer", CompOption::TypeBool);
1200
  argument[2].value().set(use_timer);
1011.1.1 by Jason Smith
trigger handles on MT
1201
1202
  /* Initiate the first available action with the arguments */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1203
  _grab_show_action->initiate()(_grab_show_action, 0, argument);
1011.1.1 by Jason Smith
trigger handles on MT
1204
}
1205
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1206
void
1207
PluginAdapter::HideGrabHandles(CompWindow* window)
1011.1.1 by Jason Smith
trigger handles on MT
1208
{
1067 by Jason Smith
some extra crash protection
1209
  if (!_grab_hide_action || !window)
1011.1.1 by Jason Smith
trigger handles on MT
1210
    return;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1211
1011.1.1 by Jason Smith
trigger handles on MT
1212
  CompOption::Vector argument;
1213
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1214
  argument.resize(2);
1215
  argument[0].setName("root", CompOption::TypeInt);
1216
  argument[0].value().set((int) screen->root());
1217
  argument[1].setName("window", CompOption::TypeInt);
1218
  argument[1].value().set((int) window->id());
1011.1.1 by Jason Smith
trigger handles on MT
1219
1220
  /* Initiate the first available action with the arguments */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1221
  _grab_hide_action->initiate()(_grab_hide_action, 0, argument);
1011.1.1 by Jason Smith
trigger handles on MT
1222
}
1223
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1224
void
1225
PluginAdapter::ToggleGrabHandles(CompWindow* window)
1011.1.1 by Jason Smith
trigger handles on MT
1226
{
1067 by Jason Smith
some extra crash protection
1227
  if (!_grab_toggle_action || !window)
1011.1.1 by Jason Smith
trigger handles on MT
1228
    return;
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1229
1011.1.1 by Jason Smith
trigger handles on MT
1230
  CompOption::Vector argument;
1231
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1232
  argument.resize(2);
1233
  argument[0].setName("root", CompOption::TypeInt);
1234
  argument[0].value().set((int) screen->root());
1235
  argument[1].setName("window", CompOption::TypeInt);
1236
  argument[1].value().set((int) window->id());
1011.1.1 by Jason Smith
trigger handles on MT
1237
1238
  /* Initiate the first available action with the arguments */
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1239
  _grab_toggle_action->initiate()(_grab_toggle_action, 0, argument);
1011.1.1 by Jason Smith
trigger handles on MT
1240
}
1195.5.1 by Marco Biscaro
Creating option to adjust the automaximize value (LP: #754214).
1241
1242
void
1307 by Neil Jagdish Patel
Update formatting to match style (as close as possible)
1243
PluginAdapter::SetCoverageAreaBeforeAutomaximize(float area)
1244
{
1195.5.1 by Marco Biscaro
Creating option to adjust the automaximize value (LP: #754214).
1245
  _coverage_area_before_automaximize = area;
1246
}
1423.1.3 by Sam Spilsbury
Simplify the input focus restore stuff and move that into
1247
1248
bool
1249
PluginAdapter::saveInputFocus()
1250
{
1251
  Window      active = m_Screen->activeWindow ();
1252
  CompWindow* cw = m_Screen->findWindow (active);
1253
1254
  if (cw)
1255
  {
1256
    _last_focused_window = cw;
1257
    return true;
1258
  }
1259
1260
  return false;
1261
}
1262
1263
bool
1264
PluginAdapter::restoreInputFocus()
1265
{
1266
  if (_last_focused_window)
1267
  {
1268
    _last_focused_window->moveInputFocusTo ();
1269
    _last_focused_window = NULL;
1270
    return true;
1271
  }
1272
  else
1273
  {
1274
    m_Screen->focusDefaultWindow ();
1275
    return false;
1276
  }
1277
1278
  return false;
1279
}
1280
1281
void
1858.17.8 by Marco Trevisan (Treviño)
Pushing back removed changes
1282
PluginAdapter::MoveResizeWindow(guint32 xid, nux::Geometry geometry)
1283
{
1284
  int w, h;
1285
  CompWindow* window = m_Screen->findWindow(xid);
1286
1287
  if (!window)
1288
    return;
1289
1290
  if (window->constrainNewWindowSize(geometry.width, geometry.height, &w, &h))
1291
  {
1292
    CompRect workarea = m_Screen->getWorkareaForOutput(window->outputDevice());
1293
    int dx = geometry.x + w - workarea.right() + window->border().right;
1294
    int dy = geometry.y + h - workarea.bottom() + window->border().bottom;
1295
1296
    if (dx > 0)
1297
      geometry.x -= dx;
1298
    if (dy > 0)
1299
      geometry.y -= dy;
1300
1301
    geometry.SetWidth(w);
1302
    geometry.SetHeight(h);
1303
  }
1304
1305
  XWindowChanges xwc;
1306
  xwc.x = geometry.x;
1307
  xwc.y = geometry.y;
1308
  xwc.width = geometry.width;
1309
  xwc.height = geometry.height;
1310
1311
  if (window->mapNum())
1312
    window->sendSyncRequest();
1313
1314
  window->configureXWindow(CWX | CWY | CWWidth | CWHeight, &xwc);
1315
}
1316
1317
void
1423.1.3 by Sam Spilsbury
Simplify the input focus restore stuff and move that into
1318
PluginAdapter::OnWindowClosed(CompWindow *w)
1319
{
1320
  if (_last_focused_window == w)
1321
    _last_focused_window = NULL;
1322
}
1323
2324.2.4 by Marco Trevisan (Treviño)
WindowManager: make it introspectable, implementation in PluginAdapter.
1324
void
1325
PluginAdapter::AddProperties(GVariantBuilder* builder)
1326
{
1327
  unity::variant::BuilderWrapper wrapper(builder);
1328
  wrapper.add(GetScreenGeometry())
1329
         .add("workspace_count", WorkspaceCount())
1330
         .add("active_window", GetActiveWindow())
1331
         .add("screen_grabbed", IsScreenGrabbed())
1332
         .add("scale_active", IsScaleActive())
1333
         .add("scale_active_for_group", IsScaleActiveForGroup())
1334
         .add("expo_active", IsExpoActive())
2370.3.1 by Christopher Lee
Added 'show desktop' details for introspection
1335
         .add("viewport_switch_running", IsViewPortSwitchStarted())
1336
         .add("showdesktop_active", _in_show_desktop);
2324.2.4 by Marco Trevisan (Treviño)
WindowManager: make it introspectable, implementation in PluginAdapter.
1337
}
2650.1.1 by Renato Araujo Oliveira Filho
Moved function "GetWindowName" from UnityWindow to WindowManager.
1338
1339
std::string
1340
PluginAdapter::GetWindowName(guint32 xid) const
1341
{
1342
  std::string name;
1343
  Atom visibleNameAtom;
1344
1345
  visibleNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_VISIBLE_NAME", 0);
1346
  name = GetUtf8Property(xid, visibleNameAtom);
1347
  if (name.empty())
1348
  {
1349
    Atom wmNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_NAME", 0);
1350
    name = GetUtf8Property(xid, wmNameAtom);
1351
  }
1352
1353
  if (name.empty())
1354
    name = GetTextProperty(xid, XA_WM_NAME);
1355
1356
  return name;
1357
}
1358
1359
std::string
1360
PluginAdapter::GetUtf8Property(guint32 xid, Atom atom) const
1361
{
1362
  Atom          type;
1363
  int           result, format;
1364
  unsigned long nItems, bytesAfter;
1365
  char          *val;
1366
  std::string   retval;
1367
  Atom          utf8StringAtom;
1368
1369
  utf8StringAtom = XInternAtom(m_Screen->dpy(), "UTF8_STRING", 0);
1370
  result = XGetWindowProperty(m_Screen->dpy(), xid, atom, 0L, 65536, False,
1371
                              utf8StringAtom, &type, &format, &nItems,
1372
                              &bytesAfter, reinterpret_cast<unsigned char **>(&val));
1373
1374
  if (result != Success)
1375
    return retval;
1376
1377
  if (type == utf8StringAtom && format == 8 && val && nItems > 0)
1378
  {
2650.1.6 by Renato Araujo Oliveira Filho
Optimized GetWindowName code.
1379
    retval = std::string(val, nItems);
2650.1.1 by Renato Araujo Oliveira Filho
Moved function "GetWindowName" from UnityWindow to WindowManager.
1380
  }
1381
  if (val)
1382
    XFree(val);
1383
1384
  return retval;
1385
}
1386
1387
std::string
1388
PluginAdapter::GetTextProperty(guint32 id, Atom atom) const
1389
{
1390
  XTextProperty text;
1391
  std::string retval;
1392
1393
  text.nitems = 0;
1394
  if (XGetTextProperty(m_Screen->dpy(), id, &text, atom))
1395
  {
1396
    if (text.value)
1397
    {
2650.1.6 by Renato Araujo Oliveira Filho
Optimized GetWindowName code.
1398
      retval = std::string(reinterpret_cast<char*>(text.value), text.nitems);
2650.1.1 by Renato Araujo Oliveira Filho
Moved function "GetWindowName" from UnityWindow to WindowManager.
1399
      XFree (text.value);
1400
    }
1401
  }
1402
1403
  return retval;
1404
}