Merge branch 'display-images' of github.com:nuew/sway

This commit is contained in:
Nuew 2016-03-24 18:16:58 -04:00
commit 51fa9de688
9 changed files with 154 additions and 110 deletions

View file

@ -8,10 +8,10 @@ irc.freenode.net).
![](https://sr.ht/NCx_.png) ![](https://sr.ht/NCx_.png)
## Rationale ## Release Signatures
I use i3 on xorg. Wayland is coming, and [i3way](http://i3way.org/) still has Releases are signed with [B22DA89A](http://pgp.mit.edu/pks/lookup?search=B22DA89A&op=index)
zero lines of source code after two years. and published [on GitHub](https://github.com/SirCmpwn/sway/releases).
## Status ## Status

View file

@ -47,7 +47,7 @@ struct ipc_response *ipc_recv_response(int socketfd) {
size_t total = 0; size_t total = 0;
while (total < ipc_header_size) { while (total < ipc_header_size) {
ssize_t received = recv(socketfd, data + total, ipc_header_size - total, 0); ssize_t received = recv(socketfd, data + total, ipc_header_size - total, 0);
if (received < 0) { if (received <= 0) {
sway_abort("Unable to receive IPC response"); sway_abort("Unable to receive IPC response");
} }
total += received; total += received;

View file

@ -4,7 +4,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <wlc/wlc.h> #include <wlc/wlc.h>
extern struct wlc_interface interface; void register_wlc_handlers();
extern uint32_t keys_pressed[32]; extern uint32_t keys_pressed[32];
#endif #endif

View file

@ -256,7 +256,7 @@ bool load_config(const char *file) {
FILE *f = fopen(path, "r"); FILE *f = fopen(path, "r");
if (!f) { if (!f) {
fprintf(stderr, "Unable to open %s for reading", path); sway_log(L_ERROR, "Unable to open %s for reading", path);
free(path); free(path);
return false; return false;
} }
@ -272,7 +272,11 @@ bool load_config(const char *file) {
update_active_bar_modifiers(); update_active_bar_modifiers();
return config_load_success; if (!config_load_success) {
sway_log(L_ERROR, "Error(s) loading config!");
}
return true;
} }
bool read_config(FILE *file, bool is_active) { bool read_config(FILE *file, bool is_active) {

View file

@ -706,38 +706,22 @@ static void handle_wlc_ready(void) {
} }
} }
struct wlc_interface interface = { void register_wlc_handlers() {
.output = { wlc_set_output_created_cb(handle_output_created);
.created = handle_output_created, wlc_set_output_destroyed_cb(handle_output_destroyed);
.destroyed = handle_output_destroyed, wlc_set_output_resolution_cb(handle_output_resolution_change);
.resolution = handle_output_resolution_change, wlc_set_output_focus_cb(handle_output_focused);
.focus = handle_output_focused, wlc_set_output_render_pre_cb(handle_output_pre_render);
.render = { wlc_set_output_render_post_cb(handle_output_post_render);
.pre = handle_output_pre_render, wlc_set_view_created_cb(handle_view_created);
.post = handle_output_post_render wlc_set_view_destroyed_cb(handle_view_destroyed);
wlc_set_view_focus_cb(handle_view_focus);
wlc_set_view_request_geometry_cb(handle_view_geometry_request);
wlc_set_view_request_state_cb(handle_view_state_request);
wlc_set_keyboard_key_cb(handle_key);
wlc_set_pointer_motion_cb(handle_pointer_motion);
wlc_set_pointer_button_cb(handle_pointer_button);
wlc_set_compositor_ready_cb(handle_wlc_ready);
wlc_set_input_created_cb(handle_input_created);
wlc_set_input_destroyed_cb(handle_input_destroyed);
} }
},
.view = {
.created = handle_view_created,
.destroyed = handle_view_destroyed,
.focus = handle_view_focus,
.request = {
.geometry = handle_view_geometry_request,
.state = handle_view_state_request
}
},
.keyboard = {
.key = handle_key
},
.pointer = {
.motion = handle_pointer_motion,
.button = handle_pointer_button
},
.compositor = {
.ready = handle_wlc_ready
},
.input = {
.created = handle_input_created,
.destroyed = handle_input_destroyed
}
};

View file

@ -53,6 +53,7 @@ void detect_proprietary() {
char *line = read_line(f); char *line = read_line(f);
if (strstr(line, "nvidia")) { if (strstr(line, "nvidia")) {
fprintf(stderr, "\x1B[1;31mWarning: Proprietary nvidia drivers do NOT support Wayland. Use nouveau.\x1B[0m\n"); fprintf(stderr, "\x1B[1;31mWarning: Proprietary nvidia drivers do NOT support Wayland. Use nouveau.\x1B[0m\n");
fprintf(stderr, "\x1B[1;31mYes, they STILL don't work with the newly announced wayland \"support\".\x1B[0m\n");
free(line); free(line);
break; break;
} }
@ -178,7 +179,6 @@ int main(int argc, char **argv) {
} else { } else {
init_log(L_ERROR); init_log(L_ERROR);
} }
setenv("WLC_DIM", "0", 0);
wlc_log_set_handler(wlc_log_handler); wlc_log_set_handler(wlc_log_handler);
detect_proprietary(); detect_proprietary();
@ -187,7 +187,8 @@ int main(int argc, char **argv) {
/* Changing code earlier than this point requires detailed review */ /* Changing code earlier than this point requires detailed review */
/* (That code runs as root on systems without logind, and wlc_init drops to /* (That code runs as root on systems without logind, and wlc_init drops to
* another user.) */ * another user.) */
if (!wlc_init(&interface, argc, argv)) { register_wlc_handlers();
if (!wlc_init2()) {
return 1; return 1;
} }
register_extensions(); register_extensions();
@ -210,8 +211,9 @@ int main(int argc, char **argv) {
} }
if (!load_config(config_path)) { if (!load_config(config_path)) {
sway_log(L_ERROR, "Error(s) loading config!"); sway_terminate(EXIT_FAILURE);
} }
if (config_path) { if (config_path) {
free(config_path); free(config_path);
} }

View file

@ -4,6 +4,7 @@ include_directories(
${CAIRO_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS}
${PAM_INCLUDE_DIRS} ${PAM_INCLUDE_DIRS}
${JSONC_INCLUDE_DIRS}
) )
add_executable(swaylock add_executable(swaylock
@ -18,6 +19,7 @@ target_link_libraries(swaylock
${CAIRO_LIBRARIES} ${CAIRO_LIBRARIES}
${PANGO_LIBRARIES} ${PANGO_LIBRARIES}
${PAM_LIBRARIES} ${PAM_LIBRARIES}
${JSONC_LIBRARIES}
m m
) )

View file

@ -2,6 +2,7 @@
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-names.h> #include <xkbcommon/xkbcommon-names.h>
#include <security/pam_appl.h> #include <security/pam_appl.h>
#include <json-c/json.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -11,6 +12,7 @@
#include "client/window.h" #include "client/window.h"
#include "client/registry.h" #include "client/registry.h"
#include "client/cairo.h" #include "client/cairo.h"
#include "ipc-client.h"
#include "log.h" #include "log.h"
#include "list.h" #include "list.h"
@ -43,7 +45,9 @@ void sway_terminate(int exit_code) {
window_teardown(window); window_teardown(window);
} }
list_free(surfaces); list_free(surfaces);
if (registry) {
registry_teardown(registry); registry_teardown(registry);
}
exit(exit_code); exit(exit_code);
} }
@ -118,6 +122,14 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
password = malloc(password_size); password = malloc(password_size);
password[0] = '\0'; password[0] = '\0';
break; break;
case XKB_KEY_BackSpace:
{
int i = strlen(password);
if (i > 0) {
password[i - 1] = '\0';
}
break;
}
default: default:
{ {
int i = strlen(password); int i = strlen(password);
@ -229,10 +241,10 @@ cairo_surface_t *load_image(char *image_path) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
struct none_one_list images = { NOL_NONE, NULL, NULL }; char *scaling_mode_str = "fit", *socket_path = NULL;
char *scaling_mode_str = "fit"; int i, num_images = 0, color_set = 0;
uint32_t color = 0xFFFFFFFF; uint32_t color = 0xFFFFFFFF;
int i; void *images;
init_log(L_INFO); init_log(L_INFO);
@ -243,7 +255,7 @@ int main(int argc, char **argv) {
{"scaling", required_argument, NULL, 's'}, {"scaling", required_argument, NULL, 's'},
{"tiling", no_argument, NULL, 't'}, {"tiling", no_argument, NULL, 't'},
{"version", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'v'},
{"window-image", required_argument, NULL, 'w'}, {"socket", required_argument, NULL, 'p'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@ -255,8 +267,10 @@ int main(int argc, char **argv) {
" -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n" " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
" -t, --tiling Same as --scaling=tile.\n" " -t, --tiling Same as --scaling=tile.\n"
" -v, --version Show the version number and quit.\n" " -v, --version Show the version number and quit.\n"
" -i, --image <path> Display the given image.\n" " -i, --image [<display>:]<path> Display the given image.\n"
" --window-image <window>:<path> Display the given image on the given window.\n"; " --socket <socket> Use the specified socket.\n";
registry = registry_poll();
int c; int c;
while (1) { while (1) {
@ -274,6 +288,7 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
color = strtol(optarg, NULL, 16); color = strtol(optarg, NULL, 16);
color_set = 1;
if (colorlen == 6) { if (colorlen == 6) {
color <<= 8; color <<= 8;
@ -283,45 +298,39 @@ int main(int argc, char **argv) {
break; break;
} }
case 'i': case 'i':
if(images.type == NOL_NONE) { {
images = (struct none_one_list) { NOL_ONE, optarg, NULL }; char *image_path = strchr(optarg, ':');
if (image_path == NULL) {
if (num_images == 0) {
images = load_image(optarg);
num_images = -1;
} else { } else {
fprintf(stderr, "only one of --image/--window-image is allowed\n"); fprintf(stderr, "display must be defined for all --images or no --images.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; } else {
case 'w': if (num_images == 0) {
if(images.type == NOL_NONE) { images = calloc(registry->outputs->length, sizeof(char*) * 2);
images = (struct none_one_list) { NOL_LIST, create_list(), create_list() }; } else if (num_images == -1) {
for(i = 0; i <= ((list_t*) images.a)->capacity; ++i) { fprintf(stderr, "display must be defined for all --images or no --images.\n");
// this isn't perfect - if you hav>e more than 10 monitors there's a small chance of
// a segfault from uninitialized data. I honestly don't think enough people have more than
// 10 monitors to care about that though.
((list_t*) images.a)->items[i] = NULL;
((list_t*) images.b)->items[i] = NULL;
}
} else if(images.type == NOL_ONE) {
fprintf(stderr, "only one of --image/--window-image is allowed\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
char *image_path; image_path[0] = '\0';
int index = strtol(optarg, &image_path, 0); ((char**) images)[num_images * 2] = optarg;
if(*image_path != ':') { ((char**) images)[num_images++ * 2 + 1] = ++image_path;
fprintf(stderr, "--window-image should be in form '<window #>:<image path>'\n");
exit(EXIT_FAILURE);
} else {
image_path++;
} }
list_arbitrary_insert(images.a, index, image_path);
break; break;
}
case 's': case 's':
scaling_mode_str = optarg; scaling_mode_str = optarg;
break; break;
case 't': case 't':
scaling_mode_str = "tile"; scaling_mode_str = "tile";
break; break;
case 'p':
socket_path = optarg;
break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
@ -355,7 +364,16 @@ int main(int argc, char **argv) {
password = malloc(password_size); password = malloc(password_size);
password[0] = '\0'; password[0] = '\0';
surfaces = create_list(); surfaces = create_list();
registry = registry_poll(); if (!socket_path) {
socket_path = get_socketpath();
if (!socket_path) {
sway_abort("Unable to retrieve socket path");
}
}
if (!registry) {
sway_abort("Unable to connect to wayland compositor");
}
if (!registry->swaylock) { if (!registry->swaylock) {
sway_abort("swaylock requires the compositor to support the swaylock extension."); sway_abort("swaylock requires the compositor to support the swaylock extension.");
@ -378,43 +396,70 @@ int main(int argc, char **argv) {
registry->input->notify = notify_key; registry->input->notify = notify_key;
if(images.type == NOL_ONE) { if (num_images >= 1) {
images.b = load_image(images.a); char **displays_paths = images;
} else if(images.type == NOL_LIST) { images = calloc(registry->outputs->length, sizeof(cairo_surface_t*));
for(i = 0; i <= ((list_t*) images.a)->length; ++i) {
if(((list_t*) images.a)->items[i] != NULL) { int socketfd = ipc_open_socket(socket_path);
list_arbitrary_insert(images.b, i, load_image(((list_t*) images.a)->items[i])); uint32_t len = 0;
char *outputs = ipc_single_command(socketfd, IPC_GET_OUTPUTS, "", &len);
struct json_object *json_outputs = json_tokener_parse(outputs);
for (i = 0; i < registry->outputs->length; ++i) {
if (displays_paths[i * 2] != NULL) {
for (int j = 0;; ++j) {
if (j >= json_object_array_length(json_outputs)) {
fprintf(stderr, "%s is not an extant display\n", displays_paths[i * 2]);
exit(EXIT_FAILURE);
}
struct json_object *dsp_name, *at_j = json_object_array_get_idx(json_outputs, j);
if (!json_object_object_get_ex(at_j, "name", &dsp_name)) {
sway_abort("display doesn't have a name field");
}
if (!strcmp(displays_paths[i * 2], json_object_get_string(dsp_name))) {
((cairo_surface_t**) images)[j] = load_image(displays_paths[i * 2 + 1]);
break;
} }
} }
} }
}
json_object_put(json_outputs);
close(socketfd);
free(displays_paths);
}
for (i = 0; i < surfaces->length; ++i) { for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i]; struct window *window = surfaces->items[i];
if (!window_prerender(window) || !window->cairo) { if (!window_prerender(window) || !window->cairo) {
continue; continue;
} }
// always render the color in case the image doesn't fully cover the screen
render_color(window, color);
if (images.type == NOL_ONE) { if (num_images == 0 || color_set) {
render_image(window, images.b, scaling_mode); render_color(window, color);
} else if(images.type == NOL_LIST) { }
if(((list_t*) images.b)->items[i] != NULL) {
render_image(window, ((list_t*) images.b)->items[i], scaling_mode); if (num_images == -1) {
render_image(window, images, scaling_mode);
} else if (num_images >= 1) {
if (((cairo_surface_t**) images)[i] != NULL) {
render_image(window, ((cairo_surface_t**) images)[i], scaling_mode);
} }
} }
window_render(window); window_render(window);
} }
if(images.type == NOL_ONE) { if (num_images == -1) {
cairo_surface_destroy(images.b); cairo_surface_destroy((cairo_surface_t*) images);
} else if(images.type == NOL_LIST) { } else if (num_images >= 1) {
for(i = 0; i <= ((list_t*) images.a)->length; ++i) { for (i = 0; i < registry->outputs->length; ++i) {
cairo_surface_destroy(((list_t*) images.b)->items[i]); if (((cairo_surface_t**) images)[i] != NULL) {
cairo_surface_destroy(((cairo_surface_t**) images)[i]);
} }
list_free(images.a); }
list_free(images.b); free(images);
} }
bool locked = false; bool locked = false;

View file

@ -23,10 +23,11 @@ Options
Show help message and quit. Show help message and quit.
*-c, \--color* <rrggbb[aa]>:: *-c, \--color* <rrggbb[aa]>::
Turn the screen into the given color instead of white. Turn the screen into the given color instead of white. If an image is in use,
also enables color display.
*-i, \--image* <path>:: *-i, \--image* [<display>:]<path>::
Display the given image. Display the given image, optionally only on the given display.
*-s, \--scaling*:: *-s, \--scaling*::
Scaling mode for images: stretch, fill, fit, center, or tile. Scaling mode for images: stretch, fill, fit, center, or tile.
@ -37,6 +38,11 @@ Options
*-v, \--version*:: *-v, \--version*::
Show the version number and quit. Show the version number and quit.
*--socket <path>*::
Use the specified socket path. Otherwise, swaymsg will ask sway where the
socket is (which is the value of $SWAYSOCK, then of $I3SOCK).
Authors Authors
------- -------