mirror of
https://github.com/swaywm/sway.git
synced 2024-12-27 15:36:29 +01:00
Initial swaylock port
This commit is contained in:
parent
a28730edee
commit
b32bf595ae
6 changed files with 327 additions and 758 deletions
|
@ -4,6 +4,24 @@
|
|||
#include "background-image.h"
|
||||
#include "cairo.h"
|
||||
|
||||
enum background_mode parse_background_mode(const char *mode) {
|
||||
if (strcmp(mode, "stretch") == 0) {
|
||||
return BACKGROUND_MODE_STRETCH;
|
||||
} else if (strcmp(mode, "fill") == 0) {
|
||||
return BACKGROUND_MODE_FILL;
|
||||
} else if (strcmp(mode, "fit") == 0) {
|
||||
return BACKGROUND_MODE_FIT;
|
||||
} else if (strcmp(mode, "center") == 0) {
|
||||
return BACKGROUND_MODE_CENTER;
|
||||
} else if (strcmp(mode, "tile") == 0) {
|
||||
return BACKGROUND_MODE_TILE;
|
||||
} else if (strcmp(mode, "solid_color") == 0) {
|
||||
return BACKGROUND_MODE_SOLID_COLOR;
|
||||
}
|
||||
wlr_log(L_ERROR, "Unsupported background mode: %s", mode);
|
||||
return BACKGROUND_MODE_INVALID;
|
||||
}
|
||||
|
||||
cairo_surface_t *load_background_image(const char *path) {
|
||||
cairo_surface_t *image;
|
||||
#ifdef HAVE_GDK_PIXBUF
|
||||
|
@ -35,8 +53,7 @@ cairo_surface_t *load_background_image(const char *path) {
|
|||
}
|
||||
|
||||
void render_background_image(cairo_t *cairo, cairo_surface_t *image,
|
||||
enum background_mode mode, int buffer_width, int buffer_height,
|
||||
int buffer_scale) {
|
||||
enum background_mode mode, int buffer_width, int buffer_height) {
|
||||
double width = cairo_image_surface_get_width(image);
|
||||
double height = cairo_image_surface_get_height(image);
|
||||
|
||||
|
@ -93,6 +110,7 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image,
|
|||
break;
|
||||
}
|
||||
case BACKGROUND_MODE_SOLID_COLOR:
|
||||
case BACKGROUND_MODE_INVALID:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,12 @@ enum background_mode {
|
|||
BACKGROUND_MODE_CENTER,
|
||||
BACKGROUND_MODE_TILE,
|
||||
BACKGROUND_MODE_SOLID_COLOR,
|
||||
BACKGROUND_MODE_INVALID,
|
||||
};
|
||||
|
||||
enum background_mode parse_background_mode(const char *mode);
|
||||
cairo_surface_t *load_background_image(const char *path);
|
||||
void render_background_image(cairo_t *cairo, cairo_surface_t *image,
|
||||
enum background_mode mode, int buffer_width, int buffer_height,
|
||||
int buffer_scale);
|
||||
enum background_mode mode, int buffer_width, int buffer_height);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,7 @@ gdk_pixbuf = dependency('gdk-pixbuf-2.0', required: false)
|
|||
pixman = dependency('pixman-1')
|
||||
libcap = dependency('libcap')
|
||||
libinput = dependency('libinput')
|
||||
libpam = cc.find_library('libpam')
|
||||
math = cc.find_library('m')
|
||||
rt = cc.find_library('rt')
|
||||
git = find_program('git', required: false)
|
||||
|
@ -105,6 +106,7 @@ subdir('swaymsg')
|
|||
subdir('client')
|
||||
subdir('swaybg')
|
||||
subdir('swaybar')
|
||||
subdir('swaylock')
|
||||
|
||||
config = configuration_data()
|
||||
config.set('sysconfdir', join_paths(prefix, sysconfdir))
|
||||
|
|
|
@ -64,15 +64,17 @@ bool is_valid_color(const char *color) {
|
|||
}
|
||||
|
||||
static void render_frame(struct swaybg_state *state) {
|
||||
state->current_buffer = get_next_buffer(state->shm, state->buffers,
|
||||
state->width * state->scale, state->height * state->scale);
|
||||
int buffer_width = state->width * state->scale,
|
||||
buffer_height = state->height * state->scale;
|
||||
state->current_buffer = get_next_buffer(state->shm,
|
||||
state->buffers, buffer_width, buffer_height);
|
||||
cairo_t *cairo = state->current_buffer->cairo;
|
||||
if (state->args->mode == BACKGROUND_MODE_SOLID_COLOR) {
|
||||
cairo_set_source_u32(cairo, state->context.color);
|
||||
cairo_paint(cairo);
|
||||
} else {
|
||||
render_background_image(cairo, state->context.image,
|
||||
state->args->mode, state->width, state->height, state->scale);
|
||||
state->args->mode, buffer_width, buffer_height);
|
||||
}
|
||||
|
||||
wl_surface_set_buffer_scale(state->surface, state->scale);
|
||||
|
@ -193,24 +195,10 @@ int main(int argc, const char **argv) {
|
|||
args.output_idx = atoi(argv[1]);
|
||||
args.path = argv[2];
|
||||
|
||||
args.mode = BACKGROUND_MODE_STRETCH;
|
||||
if (strcmp(argv[3], "stretch") == 0) {
|
||||
args.mode = BACKGROUND_MODE_STRETCH;
|
||||
} else if (strcmp(argv[3], "fill") == 0) {
|
||||
args.mode = BACKGROUND_MODE_FILL;
|
||||
} else if (strcmp(argv[3], "fit") == 0) {
|
||||
args.mode = BACKGROUND_MODE_FIT;
|
||||
} else if (strcmp(argv[3], "center") == 0) {
|
||||
args.mode = BACKGROUND_MODE_CENTER;
|
||||
} else if (strcmp(argv[3], "tile") == 0) {
|
||||
args.mode = BACKGROUND_MODE_TILE;
|
||||
} else if (strcmp(argv[3], "solid_color") == 0) {
|
||||
args.mode = BACKGROUND_MODE_SOLID_COLOR;
|
||||
} else {
|
||||
wlr_log(L_ERROR, "Unsupported background mode: %s", argv[3]);
|
||||
args.mode = parse_background_mode(argv[3]);
|
||||
if (args.mode == BACKGROUND_MODE_INVALID) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!prepare_context(&state)) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -244,10 +232,10 @@ int main(int argc, const char **argv) {
|
|||
zwlr_layer_surface_v1_set_exclusive_zone(state.layer_surface, -1);
|
||||
zwlr_layer_surface_v1_add_listener(state.layer_surface,
|
||||
&layer_surface_listener, &state);
|
||||
state.run_display = true;
|
||||
wl_surface_commit(state.surface);
|
||||
wl_display_roundtrip(state.display);
|
||||
|
||||
state.run_display = true;
|
||||
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
|
||||
// This space intentionally left blank
|
||||
}
|
||||
|
|
1010
swaylock/main.c
1010
swaylock/main.c
File diff suppressed because it is too large
Load diff
18
swaylock/meson.build
Normal file
18
swaylock/meson.build
Normal file
|
@ -0,0 +1,18 @@
|
|||
executable(
|
||||
'swaylock',
|
||||
'main.c',
|
||||
include_directories: [sway_inc],
|
||||
dependencies: [
|
||||
cairo,
|
||||
client_protos,
|
||||
gdk_pixbuf,
|
||||
libpam,
|
||||
math,
|
||||
pango,
|
||||
pangocairo,
|
||||
wayland_client,
|
||||
wlroots,
|
||||
],
|
||||
link_with: [lib_sway_common, lib_sway_client],
|
||||
install: true
|
||||
)
|
Loading…
Reference in a new issue