~3v1n0/unity/lowgfx-setting-sync

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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright (C) 2011 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: Andrea Azzarone <azzaronea@gmail.com>
 */

#include "config.h"
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <Nux/Nux.h>
#include <Nux/NuxTimerTickSource.h>
#include <Nux/WindowThread.h>
#include <NuxCore/AnimationController.h>

#include "unity-shared/BackgroundEffectHelper.h"
#include "BaseWindowRaiserImp.h"
#include "MockShortcutHint.h"
#include "ShortcutController.h"
#include "unity-shared/UnitySettings.h"

using namespace unity;

namespace unity
{
namespace shortcut
{
struct StandaloneController : Controller
{
  StandaloneController(BaseWindowRaiser::Ptr const& raiser, AbstractModeller::Ptr const& modeller)
    : Controller(raiser, modeller)
  {}

  nux::Point GetOffsetPerMonitor(int monitor) override
  {
    return nux::Point();
  }
};
}
}

struct StandaloneModeller : shortcut::AbstractModeller
{
  StandaloneModeller()
  {
    BuildFullModel();

    model_switcher.reset(new glib::TimeoutSeconds(5, [this] {
      static bool toggle = false;
      if (toggle) BuildFullModel(); else BuildLightModel();
      toggle = !toggle;
      return true;
    }));
  }

  void BuildFullModel()
  {
    std::list<shortcut::AbstractHint::Ptr> hints;

    // Launcher...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" (Hold)"),
                                                                                   _("Opens the Launcher, displays shortcuts."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher" )));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", "",
                                                                                   _("Opens Launcher keyboard navigation mode."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "keyboard_focus")));

    // FIXME: Implemstd::shared_ptr<shortcut::AbstractHint>(ent it...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", "",
                                                                                   _("Switches applications via the Launcher."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   "Super + Tab")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" + 1 to 9"),
                                                                                   _("Same as clicking on a Launcher icon."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" + Shift + 1 to 9"),
                                                                                   _("Opens a new window in the app."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", " + T",
                                                                                   _("Opens the Trash."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    // Dash...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", _(" (Tap)"),
                                                                                   _("Opens the Dash Home."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    // These are notstd::shared_ptr<shortcut::AbstractHint>( really hardcoded...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + A",
                                                                                   _("Opens the Dash App Lens."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + F",
                                                                                   _("Opens the Dash Files Lens."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + M",
                                                                                   _("Opens the Dash Music Lens."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "",
                                                                                   _("Switches between Lenses."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   "Ctrl + Tab")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "",
                                                                                   _("Moves the focus."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   _("Arrow Keys"))));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "",
                                                                                   _("Opens the currently focused item."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   _("Enter"))));

    // Hud Menu Bar
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("HUD & Menu Bar"), "", _(" (Tap)"),
                                                                                    _("Opens the HUD."),
                                                                                    shortcut::OptionType::COMPIZ_KEY,
                                                                                    "unityshell",
                                                                                    "show_hud")));

    // Is it really std::shared_ptr<shortcut::AbstractHint>(hard coded?
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("HUD & Menu Bar"), "", _(" (Hold)"),
                                                                                   _("Reveals the application menu."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   "Alt")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("HUD & Menu Bar"), "", "",
                                                                                   _("Opens the indicator menu."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "panel_first_menu")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("HUD & Menu Bar"), "", "",
                                                                                   _("Moves focus between indicators."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   _("Cursor Left or Right"))));

    // Switching
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "",
                                                                                   _("Switches between applications."),
                                                                                  shortcut::OptionType::COMPIZ_KEY,
                                                                                  "unityshell",
                                                                                  "alt_tab_forward")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "",
                                                                                   _("Switches windows of current applications."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "alt_tab_next_window")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "",
                                                                                   _("Moves the focus."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   _("Cursor Left or Right"))));

    // Workspaces
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Workspaces"), "", "",
                                                                                   _("Switches between workspaces."),
                                                                                    shortcut::OptionType::COMPIZ_KEY,
                                                                                   "expo",
                                                                                   "expo_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Workspaces"), "", "",
                                                                                   _("Switches workspaces."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   _("Arrow Keys"))));

    //hints.push_bacstd::shared_ptr<shortcut::AbstractHint>(k(new shortcut::MockHint(_("Workspaces"), "", "", _("Move focused window to other workspace."), ...)

    // Windows
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Spreads all windows in the current workspace."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "scale",
                                                                                   "initiate_output_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Minimises all windows."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "core",
                                                                                   "show_desktop_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Maximises the current window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "core",
                                                                                   "maximize_window_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Restores or minimises the current window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "core",
                                                                                   "unmaximize_or_minimize_window_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", _(" or Right"),
                                                                                   _("Semi-maximises the current window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "grid",
                                                                                   "put_left_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Closes the current window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "core",
                                                                                   "close_window_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Opens the window accessibility menu."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "core",
                                                                                   "window_menu_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Places the window in corresponding position."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   "Ctrl + Alt + Num")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Moves the window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "move",
                                                                                   "initiate_key")));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Resizes the current window."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "resize",
                                                                                   "initiate_key")));
    model = std::make_shared<shortcut::Model>(hints);
    model_changed.emit(model);
  }

  void BuildLightModel()
  {
    std::list<shortcut::AbstractHint::Ptr> hints;

    // Launcher...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" (Hold)"),
                                                                                   _("Opens the Launcher, displays shortcuts."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher" )));

    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", "",
                                                                                   _("Opens Launcher keyboard navigation mode."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "keyboard_focus")));

    // Dash...
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", _(" (Tap)"),
                                                                                   _("Opens the Dash Home."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "unityshell",
                                                                                   "show_launcher")));

    // Is it really std::shared_ptr<shortcut::AbstractHint>(hard coded?
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("HUD & Menu Bar"), "", _(" (Hold)"),
                                                                                   _("Reveals the application menu."),
                                                                                   shortcut::OptionType::HARDCODED,
                                                                                   "Alt")));

    // Switching
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "",
                                                                                   _("Switches between applications."),
                                                                                  shortcut::OptionType::COMPIZ_KEY,
                                                                                  "unityshell",
                                                                                  "alt_tab_forward")));


    // Windows
    hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "",
                                                                                   _("Spreads all windows in the current workspace."),
                                                                                   shortcut::OptionType::COMPIZ_KEY,
                                                                                   "scale",
                                                                                   "initiate_output_key")));

    model = std::make_shared<shortcut::Model>(hints);
    model_changed.emit(model);
  }

  shortcut::Model::Ptr GetCurrentModel() const
  {
    return model;
  }

  shortcut::Model::Ptr model;
  glib::Source::UniquePtr model_switcher;
};

struct ShortcutsWindow
{
  ShortcutsWindow()
    : wt(nux::CreateGUIThread("Unity Shortcut Hint Overlay", 1024, 768, 0, &ShortcutsWindow::ThreadWidgetInit, this))
    , animation_controller(tick_source)
  {}

  void Show()
  {
    wt->Run(nullptr);
  }

private:
  void Init();

  static void ThreadWidgetInit(nux::NThread* thread, void* self)
  {
    static_cast<ShortcutsWindow*>(self)->Init();
  }

  unity::Settings settings;
  std::shared_ptr<nux::WindowThread> wt;
  nux::NuxTimerTickSource tick_source;
  nux::animation::AnimationController animation_controller;
  shortcut::Controller::Ptr controller;
};

void ShortcutsWindow::Init()
{
  BackgroundEffectHelper::blur_type = BLUR_NONE;
  auto base_window_raiser_ = std::make_shared<shortcut::BaseWindowRaiserImp>();
  auto modeller = std::make_shared<StandaloneModeller>();
  controller = std::make_shared<shortcut::StandaloneController>(base_window_raiser_, modeller);
  controller->Show();
}

int main(int argc, char** argv)
{
  gtk_init(&argc, &argv);

  nux::NuxInitialize(0);
  ShortcutsWindow().Show();

  return 0;
}