forked from swaywm/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example lockscreen protocol implementation
- Loading branch information
Showing
17 changed files
with
501 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef _SWAY_LOCK_H | ||
#define _SWAY_LOCK_H | ||
|
||
#include <wlr/types/wlr_buffer.h> | ||
|
||
#define PERMALOCK_CLIENT (struct wl_client *)(-1) | ||
|
||
struct sway_lock_state { | ||
// true -> if lock screen crashes, unrecoverable | ||
bool fail_locked; | ||
// if this is not NULL, screen is locked. If the lock screen crashed, | ||
// this may be set to PERMALOCK_CLIENT . | ||
struct wl_client *client; | ||
struct wl_listener client_destroy; | ||
|
||
struct wlr_texture *permalock_message; | ||
struct wl_global *ext_unlocker_v1_global; | ||
}; | ||
|
||
// todo: need destroy | ||
void sway_lock_state_create(struct sway_lock_state *state, | ||
struct wl_display *display); | ||
struct cmd_results *run_lockscreen_cmd(const char *cmd, bool fail_locked); | ||
|
||
struct sway_output; | ||
/** Create a texture which briefly explains the permalock state. */ | ||
struct wlr_texture *draw_permalock_message(struct sway_output *output); | ||
|
||
#endif /* _SWAY_LOCK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef _SWAY_SECURITY_H | ||
#define _SWAY_SECURITY_H | ||
|
||
#include <stdbool.h> | ||
#include <wayland-server-core.h> | ||
|
||
bool security_global_filter(const struct wl_client *client, | ||
const struct wl_global *global, void *data); | ||
|
||
#endif /* _SWAY_SECURITY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<protocol name="ext_unlocker_v1"> | ||
<copyright> | ||
Copyright 2021 Manuel Stoeckl | ||
|
||
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 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="ext_unlocker_v1" version="1"> | ||
<description summary="protocol for a session (un)locker"> | ||
This protocol provides an interface for letting a special lock screen | ||
client, which was created when the session was locked, communicate to | ||
the compositor that the session should be unlocked. | ||
</description> | ||
|
||
<request name="destroy" type="destructor"> | ||
<description summary="destroy ext_unlocker_v1 object"> | ||
Announce that this object will no longer be used. | ||
</description> | ||
</request> | ||
|
||
<request name="unlock"> | ||
<description summary="unlock screen"> | ||
Let the compositor know that it should unlock the screen. | ||
|
||
After this request has been sent by the client, sending it again shall | ||
have no effect. | ||
</description> | ||
</request> | ||
</interface> | ||
</protocol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#define _POSIX_C_SOURCE 200809L | ||
#include <string.h> | ||
|
||
#include "log.h" | ||
#include "util.h" | ||
#include "stringop.h" | ||
#include "sway/commands.h" | ||
#include "sway/config.h" | ||
#include "sway/server.h" | ||
#include "sway/input/seat.h" | ||
#include "sway/output.h" | ||
|
||
struct cmd_results *cmd_lock_screen(int argc, char **argv) { | ||
struct cmd_results *error = NULL; | ||
if ((error = cmd_exec_validate(argc, argv))) { | ||
return error; | ||
} | ||
bool fail_locked; | ||
if (strcmp(argv[0], "--fail-locked") == 0) { | ||
fail_locked = true; | ||
argv++; | ||
argc--; | ||
} else if (strcmp(argv[0], "--fail-unlocked") == 0) { | ||
fail_locked = false; | ||
argv++; | ||
argc--; | ||
} else { | ||
return cmd_results_new(CMD_FAILURE, "must set either --fail-locked or --fail-unlocked"); | ||
} | ||
|
||
char *cmd; | ||
if (argc == 1 && (argv[0][0] == '\'' || argv[0][0] == '"')) { | ||
cmd = strdup(argv[0]); | ||
strip_quotes(cmd); | ||
} else { | ||
cmd = join_args(argv, argc); | ||
} | ||
|
||
if (config->reloading) { | ||
char *args = join_args(argv, argc); | ||
sway_log(SWAY_DEBUG, "Ignoring 'cmd_lock_screen %s' due to reload", args); | ||
free(args); | ||
return cmd_results_new(CMD_SUCCESS, NULL); | ||
} | ||
|
||
struct cmd_results *res = run_lockscreen_cmd(cmd, fail_locked); | ||
free(cmd); | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.