mirror of
https://github.com/jtheoof/swappy.git
synced 2024-08-16 10:10:30 +03:00
feat: init project
This commit is contained in:
parent
887582f59d
commit
efc3eccc9e
6
.gitignore
vendored
6
.gitignore
vendored
@ -50,3 +50,9 @@ modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# Build folders
|
||||
build/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
|
27
include/swappy.h
Normal file
27
include/swappy.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef _SWAPPY_H
|
||||
#define _SWAPPY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
struct swappy_state {
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_shm *shm;
|
||||
struct zwlr_layer_shell_v1 *layer_shell;
|
||||
struct zxdg_output_manager_v1 *xdg_output_manager;
|
||||
struct wl_list outputs; // mako_output::link
|
||||
struct wl_list seats; // mako_seat::link
|
||||
|
||||
struct wl_surface *surface;
|
||||
struct mako_output *surface_output;
|
||||
struct zwlr_layer_surface_v1 *layer_surface;
|
||||
struct mako_output *layer_surface_output;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
};
|
||||
|
||||
#endif
|
7
include/wayland.h
Normal file
7
include/wayland.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _WAYLAND_H
|
||||
#define _WAYLAND_H
|
||||
|
||||
bool wayland_init(struct swappy_state *state);
|
||||
void wayland_finish(struct swappy_state *state);
|
||||
|
||||
#endif
|
24
main.c
Normal file
24
main.c
Normal file
@ -0,0 +1,24 @@
|
||||
#define _POSIX_C_SOURCE 2
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-cursor.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
#include "swappy.h"
|
||||
#include "wayland.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct swappy_state state = {0};
|
||||
|
||||
state.argc = argc;
|
||||
state.argv = argv;
|
||||
|
||||
if (!wayland_init(&state)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
wayland_finish(&state);
|
||||
}
|
70
meson.build
Normal file
70
meson.build
Normal file
@ -0,0 +1,70 @@
|
||||
project(
|
||||
'swappy',
|
||||
'c',
|
||||
version: '1.0.0',
|
||||
license: 'MIT',
|
||||
meson_version: '>=0.48.0',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
'warning_level=2',
|
||||
'werror=true',
|
||||
],
|
||||
)
|
||||
|
||||
add_project_arguments('-Wno-unused-parameter', language: 'c')
|
||||
|
||||
swappy_inc = include_directories('include')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
cairo = dependency('cairo')
|
||||
realtime = cc.find_library('rt')
|
||||
wayland_client = dependency('wayland-client')
|
||||
wayland_cursor = dependency('wayland-cursor')
|
||||
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
|
||||
|
||||
##subdir('protocol')
|
||||
|
||||
executable(
|
||||
'swappy',
|
||||
files([
|
||||
'main.c',
|
||||
'wayland.c',
|
||||
]),
|
||||
dependencies: [
|
||||
cairo,
|
||||
#client_protos,
|
||||
realtime,
|
||||
wayland_client,
|
||||
wayland_cursor,
|
||||
],
|
||||
include_directories: [swappy_inc],
|
||||
install: true,
|
||||
)
|
||||
|
||||
scdoc = find_program('scdoc', required: get_option('man-pages'))
|
||||
|
||||
if scdoc.found()
|
||||
sh = find_program('sh')
|
||||
|
||||
man_pages = ['swappy.1.scd']
|
||||
|
||||
mandir = get_option('mandir')
|
||||
|
||||
foreach src : man_pages
|
||||
topic = src.split('.')[0]
|
||||
section = src.split('.')[1]
|
||||
output = '@0@.@1@'.format(topic, section)
|
||||
|
||||
custom_target(
|
||||
output,
|
||||
input: src,
|
||||
output: output,
|
||||
command: [
|
||||
sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc.path(), output)
|
||||
],
|
||||
install: true,
|
||||
install_dir: '@0@/man@1@'.format(mandir, section)
|
||||
)
|
||||
endforeach
|
||||
endif
|
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
@ -0,0 +1 @@
|
||||
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
0
swappy.1.scd
Normal file
0
swappy.1.scd
Normal file
59
wayland.c
Normal file
59
wayland.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include "swappy.h"
|
||||
|
||||
void global_cb (void *data,
|
||||
struct wl_registry *wl_registry,
|
||||
uint32_t name,
|
||||
const char *interface,
|
||||
uint32_t version) {
|
||||
|
||||
}
|
||||
|
||||
void global_remove_cb (void *data,
|
||||
struct wl_registry *wl_registry,
|
||||
uint32_t name) {
|
||||
|
||||
}
|
||||
|
||||
struct wl_registry_listener registry_listener = {
|
||||
.global = global_cb,
|
||||
.global_remove = global_remove_cb,
|
||||
};
|
||||
|
||||
bool wayland_init(struct swappy_state *state) {
|
||||
state->display = wl_display_connect(NULL);
|
||||
if (state->display == NULL) {
|
||||
fprintf(stderr, "cannot connect to wayland display\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("connected to wayland display\n");
|
||||
|
||||
|
||||
state->registry = wl_display_get_registry(state->display);
|
||||
wl_registry_add_listener(state->registry, ®istry_listener, state);
|
||||
wl_display_roundtrip(state->display);
|
||||
|
||||
if (state->compositor == NULL) {
|
||||
fprintf(stderr, "compositor doesn't support wl_compositor\n");
|
||||
return false;
|
||||
}
|
||||
if (state->shm == NULL) {
|
||||
fprintf(stderr, "compositor doesn't support wl_shm\n");
|
||||
return false;
|
||||
}
|
||||
if (state->layer_shell == NULL) {
|
||||
fprintf(stderr, "compositor doesn't support zwlr_layer_shell_v1\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wayland_finish(struct swappy_state *state) {
|
||||
wl_display_disconnect(state->display);
|
||||
printf("disconnected from wayland display\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user