~unity-team/unity/trusty-1066971

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
/*
 * Copyright 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 warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY 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
 * version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Gordon Allott <gord.allott@canonical.com>
 *              Neil Jagdish Patel <neil.patel@canonical.com>
 *
 */
#include <gtk/gtk.h>

#include "Nux/Nux.h"
#include "Nux/VLayout.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"
#include <NuxCore/Logger.h>

#include "unity-shared/BGHash.h"
#include "unity-shared/FontSettings.h"
#include "dash/DashView.h"
#include "dash/DashController.h"
#include "panel/PanelView.h"
#include "panel/PanelController.h"
#include "unity-shared/BackgroundEffectHelper.h"
#include "launcher/FavoriteStoreGSettings.h"
#include "launcher/LauncherController.h"
#include "launcher/Launcher.h"
#include "unity-shared/DashSettings.h"
#include "unity-shared/DashStyle.h"
#include "unity-shared/PanelStyle.h"
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/UBusMessages.h"

namespace
{
  static int display_width = 1280;
  static int display_height = 720;
  static gboolean no_window_decorations = FALSE;

  static GOptionEntry entries[] =
  {
    {"width", 'w', 0, G_OPTION_ARG_INT, &display_width, "Display width", NULL},
    {"height", 'h', 0, G_OPTION_ARG_INT, &display_height, "Display height", NULL},
    {"no-window-decorations", 'd', 0, G_OPTION_ARG_NONE, &no_window_decorations, "Disables the window decorations", NULL},
    {NULL}
  };
}

using namespace unity;

class UnityStandalone
{
public:
  UnityStandalone ();
  ~UnityStandalone ();

  static void InitWindowThread (nux::NThread* thread, void* InitData);
  void Init ();

  launcher::Controller::Ptr launcher_controller;
  dash::Controller::Ptr dash_controller;
  panel::Controller::Ptr panel_controller;
};

UnityStandalone::UnityStandalone ()
{
}

UnityStandalone::~UnityStandalone ()
{
}

void UnityStandalone::Init ()
{
  launcher_controller.reset(new launcher::Controller(0));
  dash_controller.reset(new dash::Controller());
  panel_controller.reset(new panel::Controller());

  dash_controller->launcher_width = launcher_controller->launcher().GetAbsoluteWidth() - 1;

  UBusManager().SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION, nullptr);
}

void UnityStandalone::InitWindowThread(nux::NThread* thread, void* InitData)
{
  UnityStandalone *self = static_cast<UnityStandalone*>(InitData);
  self->Init();
}

int main(int argc, char **argv)
{
  nux::WindowThread* wt = NULL;
  GError *error = NULL;
  GOptionContext *context;

  nux::NuxInitialize(0);
  nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
  
  context = g_option_context_new("- Unity standalone");
  g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group(context, gtk_get_option_group(TRUE));
  g_option_context_parse(context, &argc, &argv, &error);
  if (error != NULL)
  {
    g_print("Option parsiong failed: %s\n", error->message);
    g_error_free(error);
    exit(1);
  }

  gtk_init(&argc, &argv);

  BGHash bghash;
  FontSettings font_settings;

  // The instances for the pseudo-singletons.
  dash::Style dash_style;
  dash::Settings dash_settings;
  dash_settings.SetFormFactor(dash::FormFactor::NETBOOK);
  panel::Style panel_style;

  GeisAdapter geis_adapter;
  internal::FavoriteStoreGSettings favorite_store;
  BackgroundEffectHelper::blur_type = BLUR_NONE;

  UnityStandalone *standalone_runner = new UnityStandalone();
  wt = nux::CreateNuxWindow("standalone-unity",
                            display_width, display_height,
                            (no_window_decorations) ? nux::WINDOWSTYLE_NOBORDER : nux::WINDOWSTYLE_NORMAL,
                            0, /* no parent */
                            false,
                            &UnityStandalone::InitWindowThread,
                            standalone_runner);

  wt->Run(NULL);
  delete wt;
  return 0;
}