mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
implement solid color rendering for swaybg
This commit is contained in:
parent
2e4ece65da
commit
98aa59fdda
|
@ -12,6 +12,8 @@ add_library(sway-common STATIC
|
||||||
stringop.c
|
stringop.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(sway-common m)
|
||||||
|
|
||||||
if(Backtrace_FOUND)
|
if(Backtrace_FOUND)
|
||||||
set_target_properties(sway-common
|
set_target_properties(sway-common
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
|
|
@ -97,3 +97,16 @@ pid_t get_parent_pid(pid_t child) {
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t parse_color(const char *color) {
|
||||||
|
int len = strlen(color);
|
||||||
|
if (color[0] != '#' || (len != 7 && len != 9)) {
|
||||||
|
sway_log(L_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color);
|
||||||
|
return 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
uint32_t res = (uint32_t)strtol(color + 1, NULL, 16);
|
||||||
|
if (strlen(color) == 7) {
|
||||||
|
res = (res << 8) | 0xFF;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colors for a box with background, border and text colors.
|
* Colors for a box with background, border and text colors.
|
||||||
|
@ -47,11 +48,6 @@ struct config {
|
||||||
} colors;
|
} colors;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse colors defined as hex string to uint32_t.
|
|
||||||
*/
|
|
||||||
uint32_t parse_color(const char *color);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse position top|bottom|left|right.
|
* Parse position top|bottom|left|right.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -44,4 +44,10 @@ int get_modifier_names(const char **names, uint32_t modifier_masks);
|
||||||
*/
|
*/
|
||||||
pid_t get_parent_pid(pid_t pid);
|
pid_t get_parent_pid(pid_t pid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a string that represents an RGB(A) color, return a uint32_t
|
||||||
|
* version of the color.
|
||||||
|
*/
|
||||||
|
uint32_t parse_color(const char *color);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1651,11 +1651,15 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
} else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) {
|
} else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) {
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
return cmd_results_new(CMD_INVALID, "output", "Missing background file.");
|
return cmd_results_new(CMD_INVALID, "output", "Missing background file or color specification.");
|
||||||
}
|
}
|
||||||
if (i + 1 >= argc) {
|
if (i + 1 >= argc) {
|
||||||
return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode.");
|
return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode or `solid_color`.");
|
||||||
}
|
}
|
||||||
|
if (strcasecmp(argv[argc - 1], "solid_color") == 0) {
|
||||||
|
output->background = strdup(argv[argc - 2]);
|
||||||
|
output->background_option = strdup("solid_color");
|
||||||
|
} else {
|
||||||
char *src = join_args(argv + i, argc - i - 1);
|
char *src = join_args(argv + i, argc - i - 1);
|
||||||
char *mode = argv[argc - 1];
|
char *mode = argv[argc - 1];
|
||||||
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
|
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
|
||||||
|
@ -1694,6 +1698,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
i = list_seq_find(config->output_configs, output_name_cmp, name);
|
i = list_seq_find(config->output_configs, output_name_cmp, name);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
|
|
|
@ -308,6 +308,10 @@ The default colors are:
|
||||||
Sets the wallpaper for the given output to the specified file, using the given
|
Sets the wallpaper for the given output to the specified file, using the given
|
||||||
scaling mode (one of "stretch", "fill", "fit", "center", "tile").
|
scaling mode (one of "stretch", "fill", "fit", "center", "tile").
|
||||||
|
|
||||||
|
**output** <name> <background|bg> <color> solid_color::
|
||||||
|
Sets the background of the given output to the specified color. _color_ should
|
||||||
|
be specified as an _#rrggbb_ (no alpha) color.
|
||||||
|
|
||||||
**output** <name> disable::
|
**output** <name> disable::
|
||||||
Disables the specified output.
|
Disables the specified output.
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,6 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "bar/config.h"
|
#include "bar/config.h"
|
||||||
|
|
||||||
uint32_t parse_color(const char *color) {
|
|
||||||
if (color[0] != '#') {
|
|
||||||
sway_log(L_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color);
|
|
||||||
return 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
char *end;
|
|
||||||
uint32_t res = (uint32_t)strtol(color + 1, &end, 16);
|
|
||||||
if (strlen(color) == 7) {
|
|
||||||
res = (res << 8) | 0xFF;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t parse_position(const char *position) {
|
uint32_t parse_position(const char *position) {
|
||||||
if (strcmp("top", position) == 0) {
|
if (strcmp("top", position) == 0) {
|
||||||
return DESKTOP_SHELL_PANEL_POSITION_TOP;
|
return DESKTOP_SHELL_PANEL_POSITION_TOP;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "bar/config.h"
|
#include "bar/config.h"
|
||||||
#include "bar/status_line.h"
|
#include "bar/status_line.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#define I3JSON_MAXDEPTH 4
|
#define I3JSON_MAXDEPTH 4
|
||||||
#define I3JSON_UNKNOWN 0
|
#define I3JSON_UNKNOWN 0
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "wayland-desktop-shell-client-protocol.h"
|
#include "wayland-desktop-shell-client-protocol.h"
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -9,6 +11,7 @@
|
||||||
#include "client/cairo.h"
|
#include "client/cairo.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
list_t *surfaces;
|
list_t *surfaces;
|
||||||
struct registry *registry;
|
struct registry *registry;
|
||||||
|
@ -32,6 +35,23 @@ void sway_terminate(int exit_code) {
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_valid_color(const char *color) {
|
||||||
|
int len = strlen(color);
|
||||||
|
if (len != 7 || color[0] != '#') {
|
||||||
|
sway_log(L_ERROR, "%s is not a valid color for swaybg. Color should be specified as #rrggbb (no alpha).", color);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < len; ++i) {
|
||||||
|
if (!isxdigit(color[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
init_log(L_INFO);
|
init_log(L_INFO);
|
||||||
surfaces = create_list();
|
surfaces = create_list();
|
||||||
|
@ -57,6 +77,11 @@ int main(int argc, const char **argv) {
|
||||||
window_make_shell(window);
|
window_make_shell(window);
|
||||||
list_add(surfaces, window);
|
list_add(surfaces, window);
|
||||||
|
|
||||||
|
if (strcmp(argv[3], "solid_color") == 0 && is_valid_color(argv[2])) {
|
||||||
|
cairo_set_source_u32(window->cairo, parse_color(argv[2]));
|
||||||
|
cairo_paint(window->cairo);
|
||||||
|
window_render(window);
|
||||||
|
} else {
|
||||||
#ifdef WITH_GDK_PIXBUF
|
#ifdef WITH_GDK_PIXBUF
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err);
|
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(argv[2], &err);
|
||||||
|
@ -163,6 +188,7 @@ int main(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_destroy(image);
|
cairo_surface_destroy(image);
|
||||||
|
}
|
||||||
|
|
||||||
while (wl_display_dispatch(registry->display) != -1);
|
while (wl_display_dispatch(registry->display) != -1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue