Discover swaylock extension in registry

This commit is contained in:
Drew DeVault 2015-12-10 08:04:22 -05:00
parent 080a263785
commit 067ac6cfa7
4 changed files with 34 additions and 3 deletions

View file

@ -3,6 +3,7 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "wayland-desktop-shell-client-protocol.h" #include "wayland-desktop-shell-client-protocol.h"
#include "wayland-swaylock-client-protocol.h"
#include "list.h" #include "list.h"
struct output_state { struct output_state {
@ -19,6 +20,7 @@ struct registry {
struct wl_shell *shell; struct wl_shell *shell;
struct wl_shm *shm; struct wl_shm *shm;
struct desktop_shell *desktop_shell; struct desktop_shell *desktop_shell;
struct lock *swaylock;
list_t *outputs; list_t *outputs;
}; };

View file

@ -11,7 +11,6 @@
#include "list.h" #include "list.h"
list_t *surfaces; list_t *surfaces;
struct registry *registry; struct registry *registry;
enum scaling_mode { enum scaling_mode {

View file

@ -1,16 +1,43 @@
#include "wayland-desktop-shell-client-protocol.h" #include "wayland-swaylock-client-protocol.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "client/window.h" #include "client/window.h"
#include "client/registry.h" #include "client/registry.h"
#include "log.h" #include "log.h"
list_t *surfaces;
struct registry *registry;
enum scaling_mode {
SCALING_MODE_STRETCH,
SCALING_MODE_FILL,
SCALING_MODE_FIT,
SCALING_MODE_CENTER,
SCALING_MODE_TILE,
};
void sway_terminate(void) { void sway_terminate(void) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
init_log(L_INFO); init_log(L_INFO);
sway_log(L_INFO, "Hello world"); surfaces = create_list();
registry = registry_poll();
if (!registry->swaylock) {
sway_abort("swaylock requires the compositor to support the swaylock extension.");
}
int i;
for (i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = registry->outputs->items[i];
struct window *window = window_setup(registry, output->width, output->height, false);
if (!window) {
sway_abort("Failed to create surfaces.");
}
lock_set_lock_surface(registry->swaylock, output->output, window->surface);
list_add(surfaces, window);
}
return 0; return 0;
} }

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "wayland-desktop-shell-client-protocol.h" #include "wayland-desktop-shell-client-protocol.h"
#include "wayland-swaylock-client-protocol.h"
#include "client/registry.h" #include "client/registry.h"
#include "stringop.h" #include "stringop.h"
#include "log.h" #include "log.h"
@ -58,6 +59,8 @@ static void registry_global(void *data, struct wl_registry *registry,
list_add(reg->outputs, ostate); list_add(reg->outputs, ostate);
} else if (strcmp(interface, desktop_shell_interface.name) == 0) { } else if (strcmp(interface, desktop_shell_interface.name) == 0) {
reg->desktop_shell = wl_registry_bind(registry, name, &desktop_shell_interface, version); reg->desktop_shell = wl_registry_bind(registry, name, &desktop_shell_interface, version);
} else if (strcmp(interface, lock_interface.name) == 0) {
reg->swaylock = wl_registry_bind(registry, name, &lock_interface, version);
} }
} }