mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
Add logging and new windows into layout tree
This commit is contained in:
parent
2786fa2215
commit
0427fddb5a
|
@ -5,11 +5,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
#include "log.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
|
||||||
int cmd_set(struct sway_config *config, int argc, char **argv) {
|
int cmd_set(struct sway_config *config, int argc, char **argv) {
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr, "Invalid set command (expected 2 arguments, got %d)\n", argc);
|
sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
struct sway_variable *var = malloc(sizeof(struct sway_variable));
|
struct sway_variable *var = malloc(sizeof(struct sway_variable));
|
||||||
|
@ -23,7 +24,7 @@ int cmd_set(struct sway_config *config, int argc, char **argv) {
|
||||||
|
|
||||||
int cmd_bindsym(struct sway_config *config, int argc, char **argv) {
|
int cmd_bindsym(struct sway_config *config, int argc, char **argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Invalid bindsym command (expected 2 arguments, got %d)\n", argc);
|
sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
argv[0] = do_var_replacement(config, argv[0]);
|
argv[0] = do_var_replacement(config, argv[0]);
|
||||||
|
@ -39,7 +40,7 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) {
|
||||||
// TODO: Parse modifier keys
|
// TODO: Parse modifier keys
|
||||||
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE);
|
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE);
|
||||||
if (!sym) {
|
if (!sym) {
|
||||||
fprintf(stderr, "bindsym - unknown key '%s'\n", (char *)split->items[i]);
|
sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]);
|
||||||
// Ignore for now, we need to deal with modifier keys
|
// Ignore for now, we need to deal with modifier keys
|
||||||
// return 1;
|
// return 1;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +53,7 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) {
|
||||||
// TODO: Check if there are other commands with this key binding
|
// TODO: Check if there are other commands with this key binding
|
||||||
list_add(config->current_mode->bindings, binding);
|
list_add(config->current_mode->bindings, binding);
|
||||||
|
|
||||||
fprintf(stderr, "bindsym - Bound %s to command %s\n", argv[0], binding->command);
|
sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +140,7 @@ int handle_command(struct sway_config *config, char *exec) {
|
||||||
}
|
}
|
||||||
struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd);
|
struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd);
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
fprintf(stderr, "Unknown command '%s'\n", cmd);
|
sway_log(L_ERROR, "Unknown command '%s'", cmd);
|
||||||
return 0; // TODO: return error, probably
|
return 0; // TODO: return error, probably
|
||||||
}
|
}
|
||||||
int argc;
|
int argc;
|
||||||
|
|
|
@ -17,18 +17,17 @@ void handle_output_resolution_change(wlc_handle output, const struct wlc_size *f
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_view_created(wlc_handle view) {
|
bool handle_view_created(wlc_handle view) {
|
||||||
printf("View created, focusing");
|
add_view(view);
|
||||||
wlc_view_focus(view);
|
|
||||||
wlc_view_bring_to_front(view);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_view_destroyed(wlc_handle view) {
|
void handle_view_destroyed(wlc_handle view) {
|
||||||
printf("View destroyed");
|
destroy_view(view);
|
||||||
wlc_view_focus(get_topmost(wlc_view_get_output(view), 0));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_view_focus(wlc_handle view, bool focus) {
|
void handle_view_focus(wlc_handle view, bool focus) {
|
||||||
|
printf("View focused\n");
|
||||||
wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus);
|
wlc_view_set_state(view, WLC_BIT_ACTIVATED, focus);
|
||||||
|
focused_view = view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,18 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
list_t *outputs;
|
list_t *outputs;
|
||||||
|
wlc_handle focused_view;
|
||||||
|
|
||||||
|
void arrange_windows() {
|
||||||
|
}
|
||||||
|
|
||||||
void init_layout() {
|
void init_layout() {
|
||||||
outputs = create_list();
|
outputs = create_list();
|
||||||
|
focused_view = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sway_container *get_container(wlc_handle output, int *index) {
|
struct sway_container *get_container(wlc_handle output, int *index) {
|
||||||
|
@ -21,6 +27,74 @@ struct sway_container *get_container(wlc_handle output, int *index) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sway_container *get_container_for_view_recurse(wlc_handle handle, int *index, struct sway_container *parent) {
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < parent->children->length; ++j) {
|
||||||
|
struct sway_container *child = parent->children->items[j];
|
||||||
|
if (child->layout == LAYOUT_IS_VIEW) {
|
||||||
|
if (child->output == handle) {
|
||||||
|
*index = j;
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
struct sway_container *res;
|
||||||
|
if ((res = get_container_for_view_recurse(handle, index, child))) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sway_container *get_container_for_view(wlc_handle handle, int *index) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < outputs->length; ++i) {
|
||||||
|
struct sway_container *c = outputs->items[i];
|
||||||
|
struct sway_container *res;
|
||||||
|
if ((res = get_container_for_view_recurse(handle, index, c))) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_view(wlc_handle view_handle) {
|
||||||
|
struct sway_container *container;
|
||||||
|
int _;
|
||||||
|
|
||||||
|
if (focused_view == -1) { // Add it to the output container
|
||||||
|
sway_log(L_DEBUG, "Adding initial view for output", view_handle);
|
||||||
|
wlc_handle output = wlc_get_focused_output();
|
||||||
|
container = get_container(output, &_);
|
||||||
|
} else {
|
||||||
|
sway_log(L_DEBUG, "Adding view %d to output", view_handle);
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create "container" for this view
|
||||||
|
struct sway_container *view = malloc(sizeof(struct sway_container));
|
||||||
|
view->layout = LAYOUT_IS_VIEW;
|
||||||
|
view->children = NULL;
|
||||||
|
view->output = view_handle;
|
||||||
|
list_add(container->children, view);
|
||||||
|
|
||||||
|
wlc_view_focus(view_handle);
|
||||||
|
|
||||||
|
arrange_windows();
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_view(wlc_handle view) {
|
||||||
|
sway_log(L_DEBUG, "Destroying view %d", view);
|
||||||
|
|
||||||
|
int index;
|
||||||
|
struct sway_container *container = get_container_for_view(view, &index);
|
||||||
|
list_del(container->children, index);
|
||||||
|
|
||||||
|
wlc_view_focus(get_topmost(wlc_view_get_output(view), 0));
|
||||||
|
|
||||||
|
arrange_windows();
|
||||||
|
}
|
||||||
|
|
||||||
void add_output(wlc_handle output) {
|
void add_output(wlc_handle output) {
|
||||||
struct sway_container *container = malloc(sizeof(struct sway_container));
|
struct sway_container *container = malloc(sizeof(struct sway_container));
|
||||||
// TODO: Get default layout from config
|
// TODO: Get default layout from config
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
LAYOUT_IS_VIEW,
|
||||||
LAYOUT_TILE_HORIZ,
|
LAYOUT_TILE_HORIZ,
|
||||||
LAYOUT_TILE_VERT,
|
LAYOUT_TILE_VERT,
|
||||||
LAYOUT_TABBED,
|
LAYOUT_TABBED,
|
||||||
|
@ -15,12 +16,17 @@ struct sway_container {
|
||||||
wlc_handle output;
|
wlc_handle output;
|
||||||
list_t *children;
|
list_t *children;
|
||||||
container_layout_t layout;
|
container_layout_t layout;
|
||||||
|
struct sway_container *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern list_t *outputs;
|
extern list_t *outputs;
|
||||||
|
extern wlc_handle focused_view;
|
||||||
|
|
||||||
void init_layout();
|
void init_layout();
|
||||||
void add_output(wlc_handle output);
|
void add_output(wlc_handle output);
|
||||||
|
void destroy_output(wlc_handle output);
|
||||||
wlc_handle get_topmost(wlc_handle output, size_t offset);
|
wlc_handle get_topmost(wlc_handle output, size_t offset);
|
||||||
|
void destroy_view(wlc_handle view);
|
||||||
|
void add_view(wlc_handle view);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
43
sway/log.c
Normal file
43
sway/log.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#include "log.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int colored = 1;
|
||||||
|
int v = 0;
|
||||||
|
|
||||||
|
const char *verbosity_colors[] = {
|
||||||
|
"", // L_SILENT
|
||||||
|
"\x1B[1;31m", // L_ERROR
|
||||||
|
"\x1B[1;34m", // L_INFO
|
||||||
|
"\x1B[1;30m", // L_DEBUG
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_log(int verbosity) {
|
||||||
|
v = verbosity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sway_abort(char *format, ...) {
|
||||||
|
fprintf(stderr, "ERROR: ");
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sway_log(int verbosity, char* format, ...) {
|
||||||
|
if (verbosity <= v) {
|
||||||
|
int c = verbosity;
|
||||||
|
if (c > sizeof(verbosity_colors) / sizeof(char *)) {
|
||||||
|
c = sizeof(verbosity_colors) / sizeof(char *) - 1;
|
||||||
|
}
|
||||||
|
fprintf(stderr, verbosity_colors[c]);
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
vfprintf(stderr, format, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "\x1B[0m\n");
|
||||||
|
}
|
||||||
|
}
|
15
sway/log.h
Normal file
15
sway/log.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef _SWAY_LOG_H
|
||||||
|
#define _SWAY_LOG_H
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
L_SILENT = 0,
|
||||||
|
L_ERROR = 1,
|
||||||
|
L_INFO = 2,
|
||||||
|
L_DEBUG = 3,
|
||||||
|
} log_importance_t;
|
||||||
|
|
||||||
|
void init_log(int verbosity);
|
||||||
|
void sway_log(int verbosity, char* format, ...);
|
||||||
|
void sway_abort(char* format, ...);
|
||||||
|
|
||||||
|
#endif
|
|
@ -4,6 +4,7 @@
|
||||||
#include <wlc/wlc.h>
|
#include <wlc/wlc.h>
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
|
|
||||||
struct sway_config *config;
|
struct sway_config *config;
|
||||||
|
@ -27,6 +28,7 @@ void load_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
init_log(L_DEBUG); // TODO: Control this with command line arg
|
||||||
load_config();
|
load_config();
|
||||||
init_layout();
|
init_layout();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue