Add wallpapers to output command

This commit is contained in:
Drew DeVault 2015-11-19 18:55:17 -05:00
parent 79b277fe9b
commit 5728307520
5 changed files with 59 additions and 19 deletions

View file

@ -115,14 +115,28 @@ Commands
When _output_: place mouse at center of newly focused window when changing
output. When _none_: don't move mouse.
**output** <name> <resolution|res WIDTHxHEIGHT> <position|pos X,Y>::
Configures the specified output. It will use the given resolution and be
arranged at the given position in the layout tree. You may omit either of
these parameters if you only want to set one of them.
**output** <name> <resolution|res> <WIDTHxHEIGHT>::
Configures the specified output to use the given resolution.
**output** <name> <position|pos> <X,Y>::
Configures the specified output to be arranged at the given position.
**output** <name> <background|bg> <file> <mode>::
Sets the wallpaper for the given output to the specified file, using the given
scaling mode (one of "stretch", "fill", "center", "tile").
**output** <name> disable::
Disables the specified output.
**NOTES FOR THE OUTPUT COMMAND**::
You may combine output commands into one, like so:
+
output HDMI-A-1 res 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch
+
You can get a list of output names like so:
+
swaymsg -t get_outputs
**reload**::
Reloads the sway config file without restarting sway.

View file

@ -314,6 +314,28 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
}
output->x = x;
}
if (oc->background) {
int i;
for (i = 0; i < root_container.children->length; ++i) {
if (root_container.children->items[i] == output) {
break;
}
}
sway_log(L_DEBUG, "Setting background for output %d to %s", i, oc->background);
char *cmd = malloc(
strlen("swaybg ") +
(i >= 10 ? 2 : 1) +
strlen(oc->background) + 3 +
strlen(oc->background_option) + 3 +
1);
sprintf(cmd, "swaybg %d '%s' '%s'", i, oc->background, oc->background_option);
if (fork() == 0) {
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
}
free(cmd);
}
}
char *do_var_replacement(char *str) {

View file

@ -43,6 +43,11 @@ static bool handle_output_created(wlc_handle output) {
swayc_t *ws = op->children->items[0];
workspace_switch(ws);
}
// Fixes issues with backgrounds and wlc
wlc_handle prev = wlc_get_focused_output();
wlc_output_focus(output);
wlc_output_focus(prev);
return true;
}

View file

@ -28,28 +28,29 @@ int main(int argc, char **argv) {
surfaces = create_list();
registry = registry_poll();
if (argc < 2) {
sway_abort("Usage: swaybg path/to/file.png");
if (argc < 4) {
sway_abort("Do not run this program manually. See man 5 sway and look for output options.");
}
if (!registry->desktop_shell) {
sway_abort("swaybg requires the compositor to support the desktop-shell extension.");
}
int desired_output = atoi(argv[1]);
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
int i;
for (i = 0; i < registry->outputs->length; ++i) {
struct output_state *output = registry->outputs->items[i];
struct window *window = window_setup(registry, 100, 100, false);
if (!window) {
sway_abort("Failed to create surfaces.");
}
window->width = output->width;
window->height = output->height;
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
list_add(surfaces, window);
struct output_state *output = registry->outputs->items[desired_output];
struct window *window = window_setup(registry, 100, 100, false);
if (!window) {
sway_abort("Failed to create surfaces.");
}
window->width = output->width;
window->height = output->height;
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
list_add(surfaces, window);
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[1]);
char *scaling_mode = argv[3];
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
double width = cairo_image_surface_get_width(image);
double height = cairo_image_surface_get_height(image);

View file

@ -17,7 +17,6 @@
static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w) {
sway_log(L_INFO, "Set cursor");
struct window *window = data;
struct wl_cursor_image *image = window->cursor.cursor->images[0];
wl_pointer_set_cursor(pointer, serial, window->cursor.surface, image->hotspot_x, image->hotspot_y);
@ -72,7 +71,6 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t
wl_shell_surface_set_toplevel(window->shell_surface);
}
if (registry->pointer) {
sway_log(L_INFO, "Register pointer");
wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
}