Address review comments
This commit is contained in:
parent
653853062f
commit
d39bda76c4
|
@ -1,21 +1,16 @@
|
||||||
deps = [
|
lib_sway_client = static_library(
|
||||||
|
'sway-client',
|
||||||
|
files(
|
||||||
|
'pool-buffer.c',
|
||||||
|
),
|
||||||
|
dependencies: [
|
||||||
cairo,
|
cairo,
|
||||||
|
gdk_pixbuf,
|
||||||
pango,
|
pango,
|
||||||
pangocairo,
|
pangocairo,
|
||||||
wlroots,
|
wlroots,
|
||||||
wayland_client,
|
wayland_client,
|
||||||
]
|
],
|
||||||
|
|
||||||
if gdk_pixbuf.found()
|
|
||||||
deps += [gdk_pixbuf]
|
|
||||||
endif
|
|
||||||
|
|
||||||
lib_sway_client = static_library(
|
|
||||||
'sway-client',
|
|
||||||
files(
|
|
||||||
'buffer-pool.c',
|
|
||||||
),
|
|
||||||
dependencies: deps,
|
|
||||||
link_with: [lib_sway_common],
|
link_with: [lib_sway_common],
|
||||||
include_directories: sway_inc
|
include_directories: sway_inc
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include "buffer_pool.h"
|
#include "config.h"
|
||||||
|
#include "pool-buffer.h"
|
||||||
|
|
||||||
static int create_pool_file(size_t size, char **name) {
|
static int create_pool_file(size_t size, char **name) {
|
||||||
static const char template[] = "sway-client-XXXXXX";
|
static const char template[] = "sway-client-XXXXXX";
|
|
@ -1,7 +1,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
#include "cairo.h"
|
#include "cairo.h"
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#ifdef HAVE_GDK_PIXBUF
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#ifdef HAVE_GDK_PIXBUF
|
||||||
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
|
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
|
||||||
int chan = gdk_pixbuf_get_n_channels(gdkbuf);
|
int chan = gdk_pixbuf_get_n_channels(gdkbuf);
|
||||||
if (chan < 3) {
|
if (chan < 3) {
|
||||||
|
@ -124,4 +124,4 @@ cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdk
|
||||||
cairo_surface_mark_dirty(cs);
|
cairo_surface_mark_dirty(cs);
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
#endif //WITH_GDK_PIXBUF
|
#endif //HAVE_GDK_PIXBUF
|
||||||
|
|
|
@ -8,7 +8,8 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color);
|
||||||
cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
|
cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
|
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#include "config.h"
|
||||||
|
#ifdef HAVE_GDK_PIXBUF
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
|
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(
|
||||||
|
|
1
include/meson.build
Normal file
1
include/meson.build
Normal file
|
@ -0,0 +1 @@
|
||||||
|
configure_file(output: 'config.h', configuration: conf_data)
|
|
@ -38,8 +38,10 @@ math = cc.find_library('m')
|
||||||
git = find_program('git', required: false)
|
git = find_program('git', required: false)
|
||||||
a2x = find_program('a2x', required: false)
|
a2x = find_program('a2x', required: false)
|
||||||
|
|
||||||
|
conf_data = configuration_data()
|
||||||
|
|
||||||
if gdk_pixbuf.found()
|
if gdk_pixbuf.found()
|
||||||
add_project_arguments('-DWITH_GDK_PIXBUF', language : 'c')
|
conf_data.set('HAVE_GDK_PIXBUF', true)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if a2x.found()
|
if a2x.found()
|
||||||
|
@ -92,6 +94,7 @@ add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c')
|
||||||
|
|
||||||
sway_inc = include_directories('include')
|
sway_inc = include_directories('include')
|
||||||
|
|
||||||
|
subdir('include')
|
||||||
subdir('protocols')
|
subdir('protocols')
|
||||||
subdir('common')
|
subdir('common')
|
||||||
subdir('sway')
|
subdir('sway')
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -6,7 +7,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "buffer_pool.h"
|
#include "pool-buffer.h"
|
||||||
#include "cairo.h"
|
#include "cairo.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
|
@ -127,7 +128,7 @@ static void render_image(struct swaybg_state *state) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BACKGROUND_MODE_SOLID_COLOR:
|
case BACKGROUND_MODE_SOLID_COLOR:
|
||||||
// Should never happen
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
|
@ -158,7 +159,7 @@ static bool prepare_context(struct swaybg_state *state) {
|
||||||
state->context.color = parse_color(state->args->path);
|
state->context.color = parse_color(state->args->path);
|
||||||
return is_valid_color(state->args->path);
|
return is_valid_color(state->args->path);
|
||||||
}
|
}
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#ifdef HAVE_GDK_PIXBUF
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(state->args->path, &err);
|
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(state->args->path, &err);
|
||||||
if (!pixbuf) {
|
if (!pixbuf) {
|
||||||
|
@ -170,17 +171,17 @@ static bool prepare_context(struct swaybg_state *state) {
|
||||||
#else
|
#else
|
||||||
state->context.image = cairo_image_surface_create_from_png(
|
state->context.image = cairo_image_surface_create_from_png(
|
||||||
state->args->path);
|
state->args->path);
|
||||||
#endif //WITH_GDK_PIXBUF
|
#endif //HAVE_GDK_PIXBUF
|
||||||
if (!state->context.image) {
|
if (!state->context.image) {
|
||||||
wlr_log(L_ERROR, "Failed to read background image.");
|
wlr_log(L_ERROR, "Failed to read background image.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (cairo_surface_status(state->context.image) != CAIRO_STATUS_SUCCESS) {
|
if (cairo_surface_status(state->context.image) != CAIRO_STATUS_SUCCESS) {
|
||||||
wlr_log(L_ERROR, "Failed to read background image: %s."
|
wlr_log(L_ERROR, "Failed to read background image: %s."
|
||||||
#ifndef WITH_GDK_PIXBUF
|
#ifndef HAVE_GDK_PIXBUF
|
||||||
"\nSway was compiled without gdk_pixbuf support, so only"
|
"\nSway was compiled without gdk_pixbuf support, so only"
|
||||||
"\nPNG images can be loaded. This is the likely cause."
|
"\nPNG images can be loaded. This is the likely cause."
|
||||||
#endif //WITH_GDK_PIXBUF
|
#endif //HAVE_GDK_PIXBUF
|
||||||
, cairo_status_to_string(
|
, cairo_status_to_string(
|
||||||
cairo_surface_status(state->context.image)));
|
cairo_surface_status(state->context.image)));
|
||||||
return false;
|
return false;
|
||||||
|
@ -256,7 +257,6 @@ int main(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
args.output_idx = atoi(argv[1]);
|
args.output_idx = atoi(argv[1]);
|
||||||
args.path = argv[2];
|
args.path = argv[2];
|
||||||
args.mode = atoi(argv[3]);
|
|
||||||
|
|
||||||
args.mode = BACKGROUND_MODE_STRETCH;
|
args.mode = BACKGROUND_MODE_STRETCH;
|
||||||
if (strcmp(argv[3], "stretch") == 0) {
|
if (strcmp(argv[3], "stretch") == 0) {
|
||||||
|
@ -280,38 +280,20 @@ int main(int argc, const char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.display = wl_display_connect(NULL);
|
assert(state.display = wl_display_connect(NULL));
|
||||||
if (!state.display) {
|
|
||||||
wlr_log(L_ERROR, "Failed to create display\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wl_registry *registry = wl_display_get_registry(state.display);
|
struct wl_registry *registry = wl_display_get_registry(state.display);
|
||||||
wl_registry_add_listener(registry, ®istry_listener, &state);
|
wl_registry_add_listener(registry, ®istry_listener, &state);
|
||||||
wl_display_roundtrip(state.display);
|
wl_display_roundtrip(state.display);
|
||||||
|
assert(state.compositor && state.layer_shell && state.output && state.shm);
|
||||||
|
|
||||||
if (!state.compositor) {
|
assert(state.surface = wl_compositor_create_surface(state.compositor));
|
||||||
wlr_log(L_DEBUG, "wl-compositor not available");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!state.layer_shell) {
|
|
||||||
wlr_log(L_ERROR, "layer-shell not available");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.surface = wl_compositor_create_surface(state.compositor);
|
|
||||||
if (!state.surface) {
|
|
||||||
wlr_log(L_ERROR, "failed to create wl_surface");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
state.layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
state.layer_shell, state.surface, state.output,
|
state.layer_shell, state.surface, state.output,
|
||||||
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper");
|
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper");
|
||||||
if (!state.layer_surface) {
|
assert(state.layer_surface);
|
||||||
wlr_log(L_ERROR, "failed to create zwlr_layer_surface");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
zwlr_layer_surface_v1_set_size(state.layer_surface, 0, 0);
|
zwlr_layer_surface_v1_set_size(state.layer_surface, 0, 0);
|
||||||
zwlr_layer_surface_v1_set_anchor(state.layer_surface,
|
zwlr_layer_surface_v1_set_anchor(state.layer_surface,
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
||||||
|
@ -320,10 +302,10 @@ int main(int argc, const char **argv) {
|
||||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT);
|
||||||
zwlr_layer_surface_v1_add_listener(state.layer_surface,
|
zwlr_layer_surface_v1_add_listener(state.layer_surface,
|
||||||
&layer_surface_listener, &state);
|
&layer_surface_listener, &state);
|
||||||
|
state.run_display = true;
|
||||||
wl_surface_commit(state.surface);
|
wl_surface_commit(state.surface);
|
||||||
wl_display_roundtrip(state.display);
|
wl_display_roundtrip(state.display);
|
||||||
|
|
||||||
state.run_display = true;
|
|
||||||
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
|
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
|
||||||
// This space intentionally left blank
|
// This space intentionally left blank
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
deps = [
|
executable(
|
||||||
|
'swaybg',
|
||||||
|
'main.c',
|
||||||
|
include_directories: [sway_inc],
|
||||||
|
dependencies: [
|
||||||
cairo,
|
cairo,
|
||||||
|
gdk_pixbuf,
|
||||||
jsonc,
|
jsonc,
|
||||||
math,
|
math,
|
||||||
pango,
|
pango,
|
||||||
pangocairo,
|
pangocairo,
|
||||||
sway_protos,
|
sway_protos,
|
||||||
wayland_client,
|
wayland_client,
|
||||||
]
|
wlroots,
|
||||||
|
],
|
||||||
if gdk_pixbuf.found()
|
|
||||||
deps += [gdk_pixbuf]
|
|
||||||
endif
|
|
||||||
|
|
||||||
executable(
|
|
||||||
'swaybg',
|
|
||||||
'main.c',
|
|
||||||
include_directories: [sway_inc],
|
|
||||||
dependencies: deps,
|
|
||||||
link_with: [lib_sway_common, lib_sway_client],
|
link_with: [lib_sway_common, lib_sway_client],
|
||||||
install: true
|
install: true
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue