-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathdock-app.cpp
More file actions
194 lines (162 loc) · 4.9 KB
/
dock-app.cpp
File metadata and controls
194 lines (162 loc) · 4.9 KB
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
#include "dock.hpp"
#include "giomm/application.h"
#include "toplevel.hpp"
#include "toplevel-icon.hpp"
#include <iostream>
#include <gdk/wayland/gdkwayland.h>
#include <css-config.hpp>
namespace
{
extern zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_v1_impl;
}
static void registry_add_object(void *data, wl_registry *registry, uint32_t name,
const char *interface, uint32_t version)
{
if (strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0)
{
auto zwlr_toplevel_manager = (zwlr_foreign_toplevel_manager_v1*)
wl_registry_bind(registry, name,
&zwlr_foreign_toplevel_manager_v1_interface,
std::min(version, 1u));
WfDockApp::get().handle_toplevel_manager(zwlr_toplevel_manager);
}
}
static void registry_remove_object(void *data, struct wl_registry *registry, uint32_t name)
{}
static struct wl_registry_listener registry_listener =
{
®istry_add_object,
®istry_remove_object
};
class WfDockApp::impl
{
public:
std::map<zwlr_foreign_toplevel_handle_v1*,
std::unique_ptr<WfToplevel>> toplevels;
std::map<WayfireOutput*, std::unique_ptr<WfDock>> docks;
zwlr_foreign_toplevel_manager_v1 *toplevel_manager = NULL;
};
void WfDockApp::on_activate()
{
WayfireShellApp::on_activate();
new CssFromConfigInt("dock/icon_height", ".toplevel-icon {-gtk-icon-size:", "px;}");
IconProvider::load_custom_icons();
/* At this point, wayland connection has been initialized,
* and hopefully outputs have been created */
auto gdk_display = gdk_display_get_default();
auto display = gdk_wayland_display_get_wl_display(gdk_display);
wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, ®istry_listener, NULL);
wl_display_roundtrip(display);
if (!priv->toplevel_manager)
{
std::cerr << "Compositor doesn't support" <<
" wlr-foreign-toplevel-management, exiting." << std::endl;
std::exit(-1);
}
wl_registry_destroy(registry);
zwlr_foreign_toplevel_manager_v1_add_listener(priv->toplevel_manager,
&toplevel_manager_v1_impl, NULL);
}
void WfDockApp::handle_toplevel_manager(zwlr_foreign_toplevel_manager_v1 *manager)
{
priv->toplevel_manager = manager;
}
void WfDockApp::handle_new_output(WayfireOutput *output)
{
priv->docks[output] = std::unique_ptr<WfDock>(new WfDock(output));
}
void WfDockApp::handle_output_removed(WayfireOutput *output)
{
/* Send an artificial output leave.
* This is useful because in this way the toplevel can safely destroy
* its icons created on that particular output */
for (auto& toplvl : priv->toplevels)
{
toplvl.second->handle_output_leave(output->wo);
}
priv->docks.erase(output);
}
WfDock*WfDockApp::dock_for_wl_output(wl_output *output)
{
for (auto& dock : priv->docks)
{
if (dock.first->wo == output)
{
return dock.second.get();
}
}
return nullptr;
}
void WfDockApp::handle_new_toplevel(zwlr_foreign_toplevel_handle_v1 *handle)
{
priv->toplevels[handle] =
std::unique_ptr<WfToplevel>(new WfToplevel(handle));
}
void WfDockApp::handle_toplevel_closed(zwlr_foreign_toplevel_handle_v1 *handle)
{
priv->toplevels[handle]->close();
WfOption<bool> use_close_animations{"dock/show_close"};
if (use_close_animations.value())
{
Glib::signal_timeout().connect([=]
{
priv->toplevels.erase(handle);
return false;
}, 2000);
} else
{
priv->toplevels.erase(handle);
}
}
WfDockApp& WfDockApp::get()
{
if (!instance)
{
throw std::logic_error("Calling WfDockApp::get() before starting app!");
}
return dynamic_cast<WfDockApp&>(*instance.get());
}
void WfDockApp::create(int argc, char **argv)
{
if (instance)
{
throw std::logic_error("Running WfDockApp twice!");
}
instance = std::unique_ptr<WfDockApp>{new WfDockApp()};
instance->init_app();
instance->run(argc, argv);
}
std::string WfDockApp::get_application_name()
{
return "org.wayfire.dock";
}
Gio::Application::Flags WfDockApp::get_extra_application_flags()
{
return Gio::Application::Flags::NON_UNIQUE;
}
WfDockApp::WfDockApp() : WayfireShellApp(), priv(new WfDockApp::impl())
{}
WfDockApp::~WfDockApp() = default;
int main(int argc, char **argv)
{
WfDockApp::create(argc, argv);
return 0;
}
using manager_v1_t = zwlr_foreign_toplevel_manager_v1;
static void handle_manager_toplevel(void *data, manager_v1_t *manager,
zwlr_foreign_toplevel_handle_v1 *toplevel)
{
WfDockApp::get().handle_new_toplevel(toplevel);
}
static void handle_manager_finished(void *data, manager_v1_t *manager)
{
/* TODO: maybe exit? */
}
namespace
{
zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_v1_impl = {
.toplevel = handle_manager_toplevel,
.finished = handle_manager_finished,
};
}