2018-07-29 04:56:12 +02:00
|
|
|
#define _XOPEN_SOURCE 500
|
2018-07-26 03:57:19 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include "log.h"
|
|
|
|
#include "list.h"
|
2018-07-29 04:56:12 +02:00
|
|
|
#include "swaynag/config.h"
|
2018-07-29 05:15:12 +02:00
|
|
|
#include "swaynag/swaynag.h"
|
2018-07-28 15:34:25 +02:00
|
|
|
#include "swaynag/types.h"
|
2018-07-26 03:57:19 +02:00
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
static struct swaynag swaynag;
|
2018-07-26 03:57:19 +02:00
|
|
|
|
|
|
|
void sig_handler(int signal) {
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag_destroy(&swaynag);
|
2018-07-26 03:57:19 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sway_terminate(int code) {
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag_destroy(&swaynag);
|
2018-07-26 03:57:19 +02:00
|
|
|
exit(code);
|
|
|
|
}
|
|
|
|
|
2018-07-28 15:34:25 +02:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int exit_code = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
list_t *types = create_list();
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag_types_add_default(types);
|
2018-07-28 15:34:25 +02:00
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
memset(&swaynag, 0, sizeof(swaynag));
|
|
|
|
swaynag.anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
|
2018-07-28 15:34:25 +02:00
|
|
|
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
|
|
|
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag.font = strdup("pango:monospace 10");
|
|
|
|
swaynag.buttons = create_list();
|
2018-07-28 15:34:25 +02:00
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
struct swaynag_button *button_close =
|
|
|
|
calloc(sizeof(struct swaynag_button), 1);
|
2018-07-28 15:34:25 +02:00
|
|
|
button_close->text = strdup("X");
|
2018-07-29 05:15:12 +02:00
|
|
|
button_close->type = SWAYNAG_ACTION_DISMISS;
|
|
|
|
list_add(swaynag.buttons, button_close);
|
2018-07-28 15:34:25 +02:00
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag.details.button_details.text = strdup("Toggle Details");
|
|
|
|
swaynag.details.button_details.type = SWAYNAG_ACTION_EXPAND;
|
2018-07-26 03:57:19 +02:00
|
|
|
|
2018-07-28 15:34:25 +02:00
|
|
|
|
|
|
|
char *config_path = NULL;
|
|
|
|
bool debug = false;
|
2018-07-29 05:15:12 +02:00
|
|
|
int launch_status = swaynag_parse_options(argc, argv, NULL, NULL,
|
2018-07-28 15:34:25 +02:00
|
|
|
&config_path, &debug);
|
|
|
|
if (launch_status != 0) {
|
|
|
|
exit_code = launch_status;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-07-26 03:57:19 +02:00
|
|
|
wlr_log_init(debug ? WLR_DEBUG : WLR_ERROR, NULL);
|
|
|
|
|
2018-07-28 15:34:25 +02:00
|
|
|
if (!config_path) {
|
2018-07-29 05:15:12 +02:00
|
|
|
config_path = swaynag_get_config_path();
|
2018-07-28 15:34:25 +02:00
|
|
|
}
|
|
|
|
if (config_path) {
|
|
|
|
wlr_log(WLR_DEBUG, "Loading config file: %s", config_path);
|
2018-07-29 05:15:12 +02:00
|
|
|
int config_status = swaynag_load_config(config_path, &swaynag, types);
|
2018-07-28 15:34:25 +02:00
|
|
|
free(config_path);
|
|
|
|
if (config_status != 0) {
|
|
|
|
exit_code = config_status;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
2018-07-29 05:15:12 +02:00
|
|
|
int result = swaynag_parse_options(argc, argv, &swaynag, types,
|
2018-07-29 04:56:12 +02:00
|
|
|
NULL, NULL);
|
2018-07-28 15:34:25 +02:00
|
|
|
if (result != 0) {
|
|
|
|
exit_code = result;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
if (!swaynag.message) {
|
2018-07-26 03:57:19 +02:00
|
|
|
wlr_log(WLR_ERROR, "No message passed. Please provide --message/-m");
|
|
|
|
exit_code = EXIT_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
if (!swaynag.type) {
|
|
|
|
swaynag.type = swaynag_type_get(types, "error");
|
2018-07-28 15:34:25 +02:00
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag.type = swaynag_type_clone(swaynag.type);
|
|
|
|
swaynag_types_free(types);
|
2018-07-28 15:34:25 +02:00
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
if (swaynag.details.message) {
|
|
|
|
list_add(swaynag.buttons, &swaynag.details.button_details);
|
2018-07-27 07:30:35 +02:00
|
|
|
} else {
|
2018-07-29 05:15:12 +02:00
|
|
|
free(swaynag.details.button_details.text);
|
2018-07-27 07:30:35 +02:00
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Output: %s", swaynag.output.name);
|
|
|
|
wlr_log(WLR_DEBUG, "Anchors: %d", swaynag.anchors);
|
|
|
|
wlr_log(WLR_DEBUG, "Type: %s", swaynag.type->name);
|
|
|
|
wlr_log(WLR_DEBUG, "Message: %s", swaynag.message);
|
|
|
|
wlr_log(WLR_DEBUG, "Font: %s", swaynag.font);
|
2018-07-26 03:57:19 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Buttons");
|
2018-07-29 05:15:12 +02:00
|
|
|
for (int i = 0; i < swaynag.buttons->length; i++) {
|
|
|
|
struct swaynag_button *button = swaynag.buttons->items[i];
|
2018-07-26 03:57:19 +02:00
|
|
|
wlr_log(WLR_DEBUG, "\t[%s] `%s`", button->text, button->action);
|
|
|
|
}
|
|
|
|
|
|
|
|
signal(SIGTERM, sig_handler);
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag_setup(&swaynag);
|
|
|
|
swaynag_run(&swaynag);
|
2018-07-26 03:57:19 +02:00
|
|
|
return exit_code;
|
|
|
|
|
|
|
|
cleanup:
|
2018-07-29 05:15:12 +02:00
|
|
|
swaynag_types_free(types);
|
|
|
|
free(swaynag.details.button_details.text);
|
|
|
|
swaynag_destroy(&swaynag);
|
2018-07-26 03:57:19 +02:00
|
|
|
return exit_code;
|
|
|
|
}
|
|
|
|
|