Bug 1918268 - updated libwebrtc patch stack
[gecko.git] / toolkit / components / remote / nsGTKRemoteServer.cpp
blobd33d53813d9cd90312f6fd49b86d9ace615230be
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=8:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsGTKRemoteServer.h"
10 #include <gtk/gtk.h>
11 #include <gdk/gdk.h>
12 #include <gdk/gdkx.h>
14 #include "mozilla/ModuleUtils.h"
15 #include "nsAppShellCID.h"
17 #include "nsCOMPtr.h"
19 #include "nsGTKToolkit.h"
21 #ifdef MOZ_WAYLAND
22 # include "mozilla/WidgetUtilsGtk.h"
23 #endif
25 nsresult nsGTKRemoteServer::Startup(const char* aAppName,
26 const char* aProfileName) {
27 NS_ASSERTION(aAppName, "Don't pass a null appname!");
29 if (mServerWindow) {
30 return NS_ERROR_ALREADY_INITIALIZED;
33 #ifdef MOZ_WAYLAND
34 if (mozilla::widget::GdkIsWaylandDisplay()) {
35 return NS_ERROR_FAILURE;
37 #endif
39 XRemoteBaseStartup(aAppName, aProfileName);
41 mServerWindow = gtk_invisible_new();
42 gtk_widget_realize(mServerWindow);
43 HandleCommandsFor(mServerWindow);
45 return NS_OK;
48 void nsGTKRemoteServer::Shutdown() {
49 if (!mServerWindow) {
50 return;
53 gtk_widget_destroy(mServerWindow);
54 mServerWindow = nullptr;
57 void nsGTKRemoteServer::HandleCommandsFor(GtkWidget* widget) {
58 g_signal_connect(G_OBJECT(widget), "property_notify_event",
59 G_CALLBACK(HandlePropertyChange), this);
61 gtk_widget_add_events(widget, GDK_PROPERTY_CHANGE_MASK);
63 Window window = gdk_x11_window_get_xid(gtk_widget_get_window(widget));
64 nsXRemoteServer::HandleCommandsFor(window);
67 gboolean nsGTKRemoteServer::HandlePropertyChange(GtkWidget* aWidget,
68 GdkEventProperty* pevent,
69 nsGTKRemoteServer* aThis) {
70 if (pevent->state == GDK_PROPERTY_NEW_VALUE) {
71 Atom changedAtom = gdk_x11_atom_to_xatom(pevent->atom);
73 XID window = gdk_x11_window_get_xid(gtk_widget_get_window(aWidget));
74 return aThis->HandleNewProperty(
75 window, GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), pevent->time,
76 changedAtom);
78 return FALSE;