~3v1n0/unity/accelerators-controller-trigger-fix

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
212
213
214
215
216
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2013-2014 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: Marco Trevisan <marco.trevisan@canonical.com>
 */

#ifndef UNITY_DECORATION_MANAGER_PRIV
#define UNITY_DECORATION_MANAGER_PRIV

#include <unordered_map>
#include <NuxCore/NuxCore.h>
#include <NuxCore/Rect.h>
#include <UnityCore/ConnectionManager.h>
#include <UnityCore/Indicators.h>
#include <core/core.h>
#include <opengl/opengl.h>
#include <composite/composite.h>
#include <X11/extensions/shape.h>

#include "DecorationsDataPool.h"
#include "DecorationsManager.h"
#include "DecorationsInputMixer.h"
#include "EMConverter.h"

class CompRegion;

namespace unity
{
namespace decoration
{
extern Manager* manager_;

class Title;
class MenuLayout;
class SlidingLayout;
class ForceQuitDialog;

namespace cu = compiz_utils;

namespace atom
{
extern Atom _UNITY_GTK_BORDER_RADIUS;
}

struct Quads
{
  enum class Pos
  {
    TOP_LEFT = 0,
    TOP_RIGHT,
    BOTTOM_LEFT,
    BOTTOM_RIGHT,
    Size
  };

  cu::TextureQuad& operator[](Pos position) { return inner_vector_[unsigned(position)]; }
  cu::TextureQuad const& operator[](Pos position) const { return inner_vector_[unsigned(position)]; }
  std::size_t size() const { return inner_vector_.size(); }

private:
  std::array<cu::TextureQuad, size_t(Pos::Size)> inner_vector_;
};

struct Window::Impl
{
  Impl(decoration::Window*, CompWindow*);
  ~Impl();

  nux::Property<bool> active;
  sigc::signal<void, bool, ::Window> framed;

  void Update();
  void Decorate();
  void Undecorate();
  bool IsMaximized() const;
  bool FullyDecorated() const;
  bool ShadowDecorated() const;
  void RedrawDecorations();
  void Damage();
  void SetupAppMenu();
  bool ActivateMenu(std::string const&);
  void ShowForceQuitDialog(bool, Time);
  void SendFrameExtents();

private:
  void UnsetExtents();
  void SetupExtents();
  void ComputeBorderExtent(CompWindowExtents &border);
  void UpdateElements(cu::WindowFilter wf = cu::WindowFilter::NONE);
  void UpdateClientDecorationsState();
  void UpdateMonitor();
  void UpdateFrame();
  void CreateFrame(nux::Geometry const&);
  void UpdateFrameGeo(nux::Geometry const&);
  void UpdateFrameActions();
  void UnsetFrame();
  void SetupWindowEdges();
  void CleanupWindowEdges();
  void SetupWindowControls();
  void CleanupWindowControls();
  void UnsetAppMenu();
  void UpdateAppMenuVisibility();
  void SyncXShapeWithFrameRegion();
  void SyncMenusGeometries() const;
  bool ShouldBeDecorated() const;
  GLTexture* ShadowTexture() const;
  unsigned ShadowRadius() const;
  std::string const& GetMenusPanelID() const;

  void ComputeShadowQuads();
  void UpdateDecorationTextures();
  void UpdateWindowEdgesGeo();
  void UpdateForceQuitDialogPosition();
  void RenderDecorationTexture(Side, nux::Geometry const&);
  void Paint(GLMatrix const&, GLWindowPaintAttrib const&, CompRegion const&, unsigned mask);
  void Draw(GLMatrix const&, GLWindowPaintAttrib const&, CompRegion const&, unsigned mask);

  friend class Window;
  friend struct Manager::Impl;

  decoration::Window *parent_;
  ::CompWindow* win_;
  ::CompositeWindow* cwin_;
  ::GLWindow* glwin_;
  ::Window frame_;
  int monitor_;
  bool dirty_geo_;
  bool dirty_frame_;
  bool client_decorated_;
  unsigned deco_elements_;
  unsigned last_mwm_decor_;
  unsigned last_actions_;

  CompRect last_shadow_rect_;
  Quads shadow_quads_;
  nux::Geometry frame_geo_;
  CompRegion frame_region_;
  CompWindowExtents client_borders_;
  connection::Wrapper theme_changed_;
  connection::Wrapper dpi_changed_;
  connection::Wrapper grab_mouse_changed_;
  std::string last_title_;
  std::string panel_id_;
  std::vector<cu::SimpleTextureQuad> bg_textures_;
  std::shared_ptr<ForceQuitDialog> force_quit_;
  InputMixer::Ptr input_mixer_;
  Layout::Ptr top_layout_;
  uweak_ptr<MenuLayout> menus_;
  uweak_ptr<Title> title_;
  uweak_ptr<SlidingLayout> sliding_layout_;
  Item::WeakPtr grab_edge_;
  Item::Ptr edge_borders_;

  EMConverter::Ptr cv_;
};

struct Manager::Impl : sigc::trackable
{
  Impl(decoration::Manager*, menu::Manager::Ptr const&);

  Window::Ptr HandleWindow(CompWindow* cwin);
  bool HandleEventBefore(XEvent*);
  bool HandleEventAfter(XEvent*);
  bool HandleFrameEvent(XEvent*);

private:
  Window::Ptr GetWindowByXid(::Window) const;
  Window::Ptr GetWindowByFrame(::Window) const;

  bool UpdateWindow(::Window);
  void UpdateWindowsExtents();

  void SetupIntegratedMenus();
  void SetupAppMenu();
  void UnsetAppMenu();
  void BuildActiveShadowTexture();
  void BuildInactiveShadowTexture();
  cu::PixmapTexture::Ptr BuildShadowTexture(unsigned radius, nux::Color const&);
  void OnShadowOptionsChanged(bool active);
  void OnWindowFrameChanged(bool, ::Window, std::weak_ptr<decoration::Window> const&);
  bool OnMenuKeyActivated(std::string const&);

  friend class Manager;
  friend struct Window::Impl;

  DataPool::Ptr data_pool_;
  cu::PixmapTexture::Ptr active_shadow_pixmap_;
  cu::PixmapTexture::Ptr inactive_shadow_pixmap_;

  uweak_ptr<decoration::Window> active_deco_win_;
  uweak_ptr<InputMixer> last_mouse_owner_;
  std::unordered_map<CompWindow*, decoration::Window::Ptr> windows_;
  std::unordered_map<::Window, std::weak_ptr<decoration::Window>> framed_windows_;

  menu::Manager::Ptr menu_manager_;
  connection::Manager menu_connections_;
  connection::handle appmenu_connection_;
};

} // decoration namespace
} // unity namespace

#endif