feat: implement native side of xdg-decoration
This commit is contained in:
parent
bdf576602b
commit
8241fc989c
@ -143,6 +143,10 @@ tasks {
|
||||
dependsOn(generateDbus, generateDbusRegistrar)
|
||||
}
|
||||
|
||||
buildSearchableOptions {
|
||||
jvmArgs("-Dio.gitlab.jfronny.globalmenu.disable")
|
||||
}
|
||||
|
||||
// Set the JVM compatibility versions
|
||||
withType<JavaCompile> {
|
||||
sourceCompatibility = "21"
|
||||
|
@ -67,12 +67,31 @@ tasks {
|
||||
outputFile = layout.buildDirectory.file("generated/wayland/appmenu.c")
|
||||
commandLine("wayland-scanner", "private-code", inputFile.asFile.get().absolutePath, outputFile.asFile.get().absolutePath)
|
||||
}
|
||||
// shell glue is needed for a symbol used in xdg-decoration-unstable-v1
|
||||
val generateShellGlue by registering(RunToolTask::class) {
|
||||
group = "custom"
|
||||
inputFile = file("src/main/protocols/xdg-shell.xml")
|
||||
outputFile = layout.buildDirectory.file("generated/wayland/xdg-shell.c")
|
||||
commandLine("wayland-scanner", "private-code", inputFile.asFile.get().absolutePath, outputFile.asFile.get().absolutePath)
|
||||
}
|
||||
val generateDecorationHeader by registering(RunToolTask::class) {
|
||||
group = "custom"
|
||||
inputFile = file("src/main/protocols/xdg-decoration-unstable-v1.xml")
|
||||
outputFile = layout.buildDirectory.file("generated/wayland/xdg-decoration-unstable-v1.h")
|
||||
commandLine("wayland-scanner", "client-header", inputFile.asFile.get().absolutePath, outputFile.asFile.get().absolutePath)
|
||||
}
|
||||
val generateDecorationGlue by registering(RunToolTask::class) {
|
||||
group = "custom"
|
||||
inputFile = file("src/main/protocols/xdg-decoration-unstable-v1.xml")
|
||||
outputFile = layout.buildDirectory.file("generated/wayland/xdg-decoration-unstable-v1.c")
|
||||
commandLine("wayland-scanner", "private-code", inputFile.asFile.get().absolutePath, outputFile.asFile.get().absolutePath)
|
||||
}
|
||||
afterEvaluate {
|
||||
named("compileDebugCpp") {
|
||||
dependsOn(generateAppmenuHeader, generateAppmenuGlue)
|
||||
dependsOn(generateAppmenuHeader, generateAppmenuGlue, generateShellGlue, generateDecorationHeader, generateDecorationGlue)
|
||||
}
|
||||
named("compileReleaseCpp") {
|
||||
dependsOn(generateAppmenuHeader, generateAppmenuGlue)
|
||||
dependsOn(generateAppmenuHeader, generateAppmenuGlue, generateShellGlue, generateDecorationHeader, generateDecorationGlue)
|
||||
}
|
||||
}
|
||||
}
|
@ -3,18 +3,35 @@
|
||||
#include <string.h>
|
||||
#include "wayland-client-protocol.h"
|
||||
#include "appmenu.h"
|
||||
#include "xdg-decoration-unstable-v1.h"
|
||||
|
||||
// see WLComponentPeer.c in JDK
|
||||
struct WLFrame {
|
||||
jobject pad1;
|
||||
struct wl_surface *wl_surface;
|
||||
void *pad2;
|
||||
void *pad3;
|
||||
void *pad4;
|
||||
void *pad5;
|
||||
void *pad6;
|
||||
void *pad7;
|
||||
void *pad8;
|
||||
jboolean toplevel;
|
||||
union {
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
struct xdg_popup *xdg_popup;
|
||||
};
|
||||
// more stuff follows, but we don't care about it
|
||||
};
|
||||
|
||||
struct org_kde_kwin_appmenu_manager *org_kde_kwin_appmenu_manager = NULL;
|
||||
struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1 = NULL;
|
||||
|
||||
static void registry_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
|
||||
if (strcmp(interface, org_kde_kwin_appmenu_manager_interface.name) == 0) {
|
||||
org_kde_kwin_appmenu_manager = wl_registry_bind(registry, name, &org_kde_kwin_appmenu_manager_interface, 1);
|
||||
} else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
|
||||
zxdg_decoration_manager_v1 = wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,4 +81,32 @@ JNIEXPORT void JNICALL Java_io_gitlab_jfronny_globalmenu_Native_setMenuAddress(J
|
||||
org_kde_kwin_appmenu_set_address(frame, service_name, object_path);
|
||||
(*env)->ReleaseStringUTFChars(env, serviceName, service_name);
|
||||
(*env)->ReleaseStringUTFChars(env, objectPath, object_path);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_io_gitlab_jfronny_globalmenu_Native_createDecoration(JNIEnv *env, jobject obj, jlong ptr) {
|
||||
if (zxdg_decoration_manager_v1 == NULL) {
|
||||
(*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), "Decoration manager not initialized");
|
||||
return 0;
|
||||
}
|
||||
struct WLFrame *frame = (struct WLFrame *) ptr;
|
||||
if (!frame->toplevel) {
|
||||
(*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), "Not a toplevel");
|
||||
return 0;
|
||||
}
|
||||
return (jlong) (intptr_t) zxdg_decoration_manager_v1_get_toplevel_decoration(zxdg_decoration_manager_v1, frame->xdg_toplevel);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_io_gitlab_jfronny_globalmenu_Native_destroyDecoration(JNIEnv *env, jobject obj, jlong ptr) {
|
||||
struct zxdg_toplevel_decoration_v1 *frame = (struct zxdg_toplevel_decoration_v1 *) ptr;
|
||||
zxdg_toplevel_decoration_v1_unset_mode(frame);
|
||||
zxdg_toplevel_decoration_v1_destroy(frame);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_io_gitlab_jfronny_globalmenu_Native_setDecoration(JNIEnv *env, jobject obj, jlong ptr, jint mode) {
|
||||
struct zxdg_toplevel_decoration_v1 *frame = (struct zxdg_toplevel_decoration_v1 *) ptr;
|
||||
if (mode) {
|
||||
zxdg_toplevel_decoration_v1_set_mode(frame, mode);
|
||||
} else {
|
||||
zxdg_toplevel_decoration_v1_unset_mode(frame);
|
||||
}
|
||||
}
|
156
native/src/main/protocols/xdg-decoration-unstable-v1.xml
Normal file
156
native/src/main/protocols/xdg-decoration-unstable-v1.xml
Normal file
@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="xdg_decoration_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2018 Simon Ser
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<interface name="zxdg_decoration_manager_v1" version="1">
|
||||
<description summary="window decoration manager">
|
||||
This interface allows a compositor to announce support for server-side
|
||||
decorations.
|
||||
|
||||
A window decoration is a set of window controls as deemed appropriate by
|
||||
the party managing them, such as user interface components used to move,
|
||||
resize and change a window's state.
|
||||
|
||||
A client can use this protocol to request being decorated by a supporting
|
||||
compositor.
|
||||
|
||||
If compositor and client do not negotiate the use of a server-side
|
||||
decoration using this protocol, clients continue to self-decorate as they
|
||||
see fit.
|
||||
|
||||
Warning! The protocol described in this file is experimental and
|
||||
backward incompatible changes may be made. Backward compatible changes
|
||||
may be added together with the corresponding interface version bump.
|
||||
Backward incompatible changes are done by bumping the version number in
|
||||
the protocol and interface names and resetting the interface version.
|
||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
||||
version number in the protocol and interface names are removed and the
|
||||
interface version number is reset.
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the decoration manager object">
|
||||
Destroy the decoration manager. This doesn't destroy objects created
|
||||
with the manager.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<request name="get_toplevel_decoration">
|
||||
<description summary="create a new toplevel decoration object">
|
||||
Create a new decoration object associated with the given toplevel.
|
||||
|
||||
Creating an xdg_toplevel_decoration from an xdg_toplevel which has a
|
||||
buffer attached or committed is a client error, and any attempts by a
|
||||
client to attach or manipulate a buffer prior to the first
|
||||
xdg_toplevel_decoration.configure event must also be treated as
|
||||
errors.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zxdg_toplevel_decoration_v1"/>
|
||||
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zxdg_toplevel_decoration_v1" version="1">
|
||||
<description summary="decoration object for a toplevel surface">
|
||||
The decoration object allows the compositor to toggle server-side window
|
||||
decorations for a toplevel surface. The client can request to switch to
|
||||
another mode.
|
||||
|
||||
The xdg_toplevel_decoration object must be destroyed before its
|
||||
xdg_toplevel.
|
||||
</description>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="unconfigured_buffer" value="0"
|
||||
summary="xdg_toplevel has a buffer attached before configure"/>
|
||||
<entry name="already_constructed" value="1"
|
||||
summary="xdg_toplevel already has a decoration object"/>
|
||||
<entry name="orphaned" value="2"
|
||||
summary="xdg_toplevel destroyed before the decoration object"/>
|
||||
</enum>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the decoration object">
|
||||
Switch back to a mode without any server-side decorations at the next
|
||||
commit.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<enum name="mode">
|
||||
<description summary="window decoration modes">
|
||||
These values describe window decoration modes.
|
||||
</description>
|
||||
<entry name="client_side" value="1"
|
||||
summary="no server-side window decoration"/>
|
||||
<entry name="server_side" value="2"
|
||||
summary="server-side window decoration"/>
|
||||
</enum>
|
||||
|
||||
<request name="set_mode">
|
||||
<description summary="set the decoration mode">
|
||||
Set the toplevel surface decoration mode. This informs the compositor
|
||||
that the client prefers the provided decoration mode.
|
||||
|
||||
After requesting a decoration mode, the compositor will respond by
|
||||
emitting an xdg_surface.configure event. The client should then update
|
||||
its content, drawing it without decorations if the received mode is
|
||||
server-side decorations. The client must also acknowledge the configure
|
||||
when committing the new content (see xdg_surface.ack_configure).
|
||||
|
||||
The compositor can decide not to use the client's mode and enforce a
|
||||
different mode instead.
|
||||
|
||||
Clients whose decoration mode depend on the xdg_toplevel state may send
|
||||
a set_mode request in response to an xdg_surface.configure event and wait
|
||||
for the next xdg_surface.configure event to prevent unwanted state.
|
||||
Such clients are responsible for preventing configure loops and must
|
||||
make sure not to send multiple successive set_mode requests with the
|
||||
same decoration mode.
|
||||
</description>
|
||||
<arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
|
||||
</request>
|
||||
|
||||
<request name="unset_mode">
|
||||
<description summary="unset the decoration mode">
|
||||
Unset the toplevel surface decoration mode. This informs the compositor
|
||||
that the client doesn't prefer a particular decoration mode.
|
||||
|
||||
This request has the same semantics as set_mode.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<event name="configure">
|
||||
<description summary="notify a decoration mode change">
|
||||
The configure event configures the effective decoration mode. The
|
||||
configured state should not be applied immediately. Clients must send an
|
||||
ack_configure in response to this event. See xdg_surface.configure and
|
||||
xdg_surface.ack_configure for details.
|
||||
|
||||
A configure event can be sent at any time. The specified mode must be
|
||||
obeyed by the client.
|
||||
</description>
|
||||
<arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
1382
native/src/main/protocols/xdg-shell.xml
Normal file
1382
native/src/main/protocols/xdg-shell.xml
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user