~ted/unity/menu-ref

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jason Smith <jason.smith@canonical.com>
 */

#ifndef PLUGINADAPTER_H
#define PLUGINADAPTER_H

/* Compiz */
#include <core/core.h>
#include <core/atoms.h>

#include <sigc++/sigc++.h>

#include "WindowManager.h"

typedef struct
{
  unsigned long flags;
  unsigned long functions;
  unsigned long decorations;
  long input_mode;
  unsigned long status;
} MotifWmHints, MwmHints;

class MultiActionList
{
public:

  MultiActionList(int n) :
    m_ActionList(n),
    _primary_action(NULL) {};

  void InitiateAll(CompOption::Vector& extraArgs, int state);
  void TerminateAll(CompOption::Vector& extraArgs);

  void AddNewAction(CompAction*, bool primary);
  void RemoveAction(CompAction*);
private:

  std::list <CompAction*> m_ActionList;
  CompAction*              _primary_action;
};


class PluginAdapter : public sigc::trackable, public WindowManager
{
public:
  static PluginAdapter* Default();

  static void Initialize(CompScreen* screen);

  nux::Property<bool> bias_active_to_viewport;

  ~PluginAdapter();

  void SetScaleAction(MultiActionList& scale);
  void SetExpoAction(MultiActionList& expo);

  void SetShowHandlesAction(CompAction* action)
  {
    _grab_show_action = action;
  }
  void SetHideHandlesAction(CompAction* action)
  {
    _grab_hide_action = action;
  }
  void SetToggleHandlesAction(CompAction* action)
  {
    _grab_toggle_action = action;
  }

  void OnWindowClosed (CompWindow *);
  void OnScreenGrabbed();
  void OnScreenUngrabbed();

  void OnShowDesktop ();
  void OnLeaveDesktop ();

  void TerminateScale();
  bool IsScaleActive() const;
  bool IsScaleActiveForGroup() const;

  void InitiateExpo();
  bool IsExpoActive() const;

  bool IsWallActive() const;

  void ShowGrabHandles(CompWindow* window, bool use_timer);
  void HideGrabHandles(CompWindow* window);
  void ToggleGrabHandles(CompWindow* window);

  void Notify(CompWindow* window, CompWindowNotify notify);
  void NotifyMoved(CompWindow* window, int x, int y);
  void NotifyResized(CompWindow* window, int x, int y, int w, int h);
  void NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state);
  void NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option);
  void NotifyNewDecorationState(guint32 xid);

  guint32 GetActiveWindow() const;

  void Decorate(guint32 xid);
  void Undecorate(guint32 xid);

  // WindowManager implementation
  bool IsWindowMaximized(guint xid) const;
  bool IsWindowDecorated(guint xid);
  bool IsWindowOnCurrentDesktop(guint xid) const;
  bool IsWindowObscured(guint xid) const;
  bool IsWindowMapped(guint xid) const;
  bool IsWindowVisible(guint32 xid) const;
  bool IsWindowOnTop(guint32 xid) const;
  bool IsWindowClosable(guint32 xid) const;
  bool IsWindowMinimizable(guint32 xid) const;
  bool IsWindowMaximizable(guint32 xid) const;

  void Restore(guint32 xid);
  void RestoreAt(guint32 xid, int x, int y);
  void Minimize(guint32 xid);
  void Close(guint32 xid);
  void Activate(guint32 xid);
  void Raise(guint32 xid);
  void Lower(guint32 xid);

  void ShowDesktop();
  bool InShowDesktop() const;

  void SetWindowIconGeometry(Window window, nux::Geometry const& geo);

  void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor = -1, bool only_top_win = true);
  bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force);

  bool IsScreenGrabbed() const;
  bool IsViewPortSwitchStarted() const;

  unsigned long long GetWindowActiveNumber (guint32 xid) const;

  bool MaximizeIfBigEnough(CompWindow* window) const;

  int GetWindowMonitor(guint32 xid) const;
  nux::Geometry GetWindowGeometry(guint32 xid) const;
  nux::Geometry GetWindowSavedGeometry(guint32 xid) const;
  nux::Geometry GetScreenGeometry() const;
  nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const;
  std::string GetWindowName(guint32 xid) const;

  void CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any);

  int WorkspaceCount() const;

  void SetCoverageAreaBeforeAutomaximize(float area);

  bool saveInputFocus ();
  bool restoreInputFocus ();

  void MoveResizeWindow(guint32 xid, nux::Geometry geometry);

protected:
  PluginAdapter(CompScreen* screen);
  void AddProperties(GVariantBuilder* builder);

private:
  std::string MatchStringForXids(std::vector<Window> *windows);
  void InitiateScale(std::string const& match, int state = 0);

  bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const;
  void SetMwmWindowHints(Window xid, MotifWmHints* new_hints);

  Window GetTopMostValidWindowInViewport() const;

  std::string GetTextProperty(guint32 xid, Atom atom) const;
  std::string GetUtf8Property(guint32 xid, Atom atom) const;

  CompScreen* m_Screen;
  MultiActionList m_ExpoActionList;
  MultiActionList m_ScaleActionList;

  bool _spread_state;
  bool _spread_windows_state;
  bool _expo_state;
  bool _vp_switch_started;

  CompAction* _grab_show_action;
  CompAction* _grab_hide_action;
  CompAction* _grab_toggle_action;

  float _coverage_area_before_automaximize;

  bool _in_show_desktop;
  CompWindow* _last_focused_window;

  std::map<guint32, unsigned int> _window_decoration_state;

  static PluginAdapter* _default;
};

#endif