1
1
mirror of https://github.com/swaywm/sway synced 2024-11-23 00:51:58 +01:00

Address review comments

This commit is contained in:
Drew DeVault 2018-03-28 12:21:50 -04:00
parent 653853062f
commit d39bda76c4
9 changed files with 50 additions and 71 deletions

@ -1,21 +1,16 @@
deps = [
lib_sway_client = static_library(
'sway-client',
files(
'pool-buffer.c',
),
dependencies: [
cairo,
gdk_pixbuf,
pango,
pangocairo,
wlroots,
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],
include_directories: sway_inc
)

@ -8,7 +8,8 @@
#include <pango/pangocairo.h>
#include <unistd.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 const char template[] = "sway-client-XXXXXX";

@ -1,7 +1,7 @@
#include <stdint.h>
#include <cairo/cairo.h>
#include "cairo.h"
#ifdef WITH_GDK_PIXBUF
#ifdef HAVE_GDK_PIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
@ -30,7 +30,7 @@ cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image,
return new;
}
#ifdef WITH_GDK_PIXBUF
#ifdef HAVE_GDK_PIXBUF
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
int chan = gdk_pixbuf_get_n_channels(gdkbuf);
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);
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,
int width, int height);
#ifdef WITH_GDK_PIXBUF
#include "config.h"
#ifdef HAVE_GDK_PIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h>
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(

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)
a2x = find_program('a2x', required: false)
conf_data = configuration_data()
if gdk_pixbuf.found()
add_project_arguments('-DWITH_GDK_PIXBUF', language : 'c')
conf_data.set('HAVE_GDK_PIXBUF', true)
endif
if a2x.found()
@ -92,6 +94,7 @@ add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c')
sway_inc = include_directories('include')
subdir('include')
subdir('protocols')
subdir('common')
subdir('sway')

@ -1,3 +1,4 @@
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
@ -6,7 +7,7 @@
#include <time.h>
#include <wayland-client.h>
#include <wlr/util/log.h>
#include "buffer_pool.h"
#include "pool-buffer.h"
#include "cairo.h"
#include "util.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -127,7 +128,7 @@ static void render_image(struct swaybg_state *state) {
break;
}
case BACKGROUND_MODE_SOLID_COLOR:
// Should never happen
assert(0);
break;
}
cairo_paint(cairo);
@ -158,7 +159,7 @@ static bool prepare_context(struct swaybg_state *state) {
state->context.color = parse_color(state->args->path);
return is_valid_color(state->args->path);
}
#ifdef WITH_GDK_PIXBUF
#ifdef HAVE_GDK_PIXBUF
GError *err = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(state->args->path, &err);
if (!pixbuf) {
@ -170,17 +171,17 @@ static bool prepare_context(struct swaybg_state *state) {
#else
state->context.image = cairo_image_surface_create_from_png(
state->args->path);
#endif //WITH_GDK_PIXBUF
#endif //HAVE_GDK_PIXBUF
if (!state->context.image) {
wlr_log(L_ERROR, "Failed to read background image.");
return false;
}
if (cairo_surface_status(state->context.image) != CAIRO_STATUS_SUCCESS) {
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"
"\nPNG images can be loaded. This is the likely cause."
#endif //WITH_GDK_PIXBUF
#endif //HAVE_GDK_PIXBUF
, cairo_status_to_string(
cairo_surface_status(state->context.image)));
return false;
@ -256,7 +257,6 @@ int main(int argc, const char **argv) {
}
args.output_idx = atoi(argv[1]);
args.path = argv[2];
args.mode = atoi(argv[3]);
args.mode = BACKGROUND_MODE_STRETCH;
if (strcmp(argv[3], "stretch") == 0) {
@ -280,38 +280,20 @@ int main(int argc, const char **argv) {
return 1;
}
state.display = wl_display_connect(NULL);
if (!state.display) {
wlr_log(L_ERROR, "Failed to create display\n");
return 1;
}
assert(state.display = wl_display_connect(NULL));
struct wl_registry *registry = wl_display_get_registry(state.display);
wl_registry_add_listener(registry, &registry_listener, &state);
wl_display_roundtrip(state.display);
assert(state.compositor && state.layer_shell && state.output && state.shm);
if (!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;
}
assert(state.surface = wl_compositor_create_surface(state.compositor));
state.layer_surface = zwlr_layer_shell_v1_get_layer_surface(
state.layer_shell, state.surface, state.output,
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper");
if (!state.layer_surface) {
wlr_log(L_ERROR, "failed to create zwlr_layer_surface");
return 1;
}
assert(state.layer_surface);
zwlr_layer_surface_v1_set_size(state.layer_surface, 0, 0);
zwlr_layer_surface_v1_set_anchor(state.layer_surface,
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_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
}

@ -1,22 +1,18 @@
deps = [
executable(
'swaybg',
'main.c',
include_directories: [sway_inc],
dependencies: [
cairo,
gdk_pixbuf,
jsonc,
math,
pango,
pangocairo,
sway_protos,
wayland_client,
]
if gdk_pixbuf.found()
deps += [gdk_pixbuf]
endif
executable(
'swaybg',
'main.c',
include_directories: [sway_inc],
dependencies: deps,
wlroots,
],
link_with: [lib_sway_common, lib_sway_client],
install: true
)