Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Initialize Wayland socket and rig up some globals
  • Loading branch information
ddevault committed Feb 23, 2018
1 parent f89092e commit b45c651
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -3,7 +3,8 @@
This is a demonstration Wayland compositor that accompanies a series of blog
posts written for [drewdevault.com](https://drewdevault.com).

- **[Part 1: Hello wlroots](https://drewdevault.com/2018/02/17/Writing-a-Wayland-compositor-1.html)** (you are here)
- [Part 1: Hello wlroots](https://drewdevault.com/2018/02/17/Writing-a-Wayland-compositor-1.html)
- **[Part 2: Rigging up the server](https://drewdevault.com/2018/02/22/Writing-a-Wayland-compositor-2.html)** (you are here)

## Compiling

Expand Down
18 changes: 18 additions & 0 deletions src/main.c
Expand Up @@ -6,6 +6,10 @@
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/render.h>
#include <wlr/types/wlr_screenshooter.h>
#include <wlr/types/wlr_gamma_control.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_primary_selection.h>

struct mcw_server {
struct wl_display *wl_display;
Expand Down Expand Up @@ -95,6 +99,8 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
output->frame.notify = output_frame_notify;
wl_signal_add(&wlr_output->events.frame, &output->frame);

wlr_output_create_global(wlr_output);
}

int main(int argc, char **argv) {
Expand All @@ -113,12 +119,24 @@ int main(int argc, char **argv) {
server.new_output.notify = new_output_notify;
wl_signal_add(&server.backend->events.new_output, &server.new_output);

const char *socket = wl_display_add_socket_auto(server.wl_display);
assert(socket);

if (!wlr_backend_start(server.backend)) {
fprintf(stderr, "Failed to start backend\n");
wl_display_destroy(server.wl_display);
return 1;
}

printf("Running compositor on wayland display '%s'\n", socket);
setenv("WAYLAND_DISPLAY", socket, true);

wl_display_init_shm(server.wl_display);
wlr_gamma_control_manager_create(server.wl_display);
wlr_screenshooter_create(server.wl_display);
wlr_primary_selection_device_manager_create(server.wl_display);
wlr_idle_create(server.wl_display);

wl_display_run(server.wl_display);
wl_display_destroy(server.wl_display);
return 0;
Expand Down

0 comments on commit b45c651

Please sign in to comment.