mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Merge pull request #15 from taiyu-len/master
destroys empty workspace + minor fixes
This commit is contained in:
commit
e62e294366
9 changed files with 33 additions and 15 deletions
|
@ -360,7 +360,7 @@ struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *lin
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int handle_command(struct sway_config *config, char *exec) {
|
bool handle_command(struct sway_config *config, char *exec) {
|
||||||
sway_log(L_INFO, "Handling command '%s'", exec);
|
sway_log(L_INFO, "Handling command '%s'", exec);
|
||||||
char *ptr, *cmd;
|
char *ptr, *cmd;
|
||||||
bool exec_success;
|
bool exec_success;
|
||||||
|
|
|
@ -8,6 +8,6 @@ struct cmd_handler {
|
||||||
bool (*handle)(struct sway_config *config, int argc, char **argv);
|
bool (*handle)(struct sway_config *config, int argc, char **argv);
|
||||||
};
|
};
|
||||||
|
|
||||||
int handle_command(struct sway_config *config, char *command);
|
bool handle_command(struct sway_config *config, char *command);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
bool load_config() {
|
bool load_config() {
|
||||||
|
sway_log(L_INFO, "Loading config");
|
||||||
// TODO: Allow use of more config file locations
|
// TODO: Allow use of more config file locations
|
||||||
const char *name = "/.sway/config";
|
const char *name = "/.sway/config";
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
@ -65,7 +66,7 @@ struct sway_config *read_config(FILE *file, bool is_active) {
|
||||||
goto _continue;
|
goto _continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!temp_depth && handle_command(config, line) != 0) {
|
if (!temp_depth && handle_command(config, line) != true) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@ _continue:
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (success == false) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_layout() {
|
void init_layout(void) {
|
||||||
root_container.type = C_ROOT;
|
root_container.type = C_ROOT;
|
||||||
root_container.layout = L_NONE;
|
root_container.layout = L_NONE;
|
||||||
root_container.children = create_list();
|
root_container.children = create_list();
|
||||||
|
@ -128,6 +128,9 @@ void init_layout() {
|
||||||
|
|
||||||
void free_swayc(swayc_t *container) {
|
void free_swayc(swayc_t *container) {
|
||||||
// NOTE: Does not handle moving children into a different container
|
// NOTE: Does not handle moving children into a different container
|
||||||
|
if (container->parent) {
|
||||||
|
remove_container_from_parent(container->parent, container);
|
||||||
|
}
|
||||||
list_free(container->children);
|
list_free(container->children);
|
||||||
if (container->name) {
|
if (container->name) {
|
||||||
free(container->name);
|
free(container->name);
|
||||||
|
|
|
@ -45,7 +45,7 @@ typedef struct sway_container swayc_t;
|
||||||
|
|
||||||
extern swayc_t root_container;
|
extern swayc_t root_container;
|
||||||
|
|
||||||
void init_layout();
|
void init_layout(void);
|
||||||
void add_child(swayc_t *parent, swayc_t *child);
|
void add_child(swayc_t *parent, swayc_t *child);
|
||||||
void add_output(wlc_handle output);
|
void add_output(wlc_handle output);
|
||||||
void destroy_output(wlc_handle output);
|
void destroy_output(wlc_handle output);
|
||||||
|
@ -58,6 +58,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da
|
||||||
swayc_t *get_focused_container(swayc_t *parent);
|
swayc_t *get_focused_container(swayc_t *parent);
|
||||||
int remove_container_from_parent(swayc_t *parent, swayc_t *container);
|
int remove_container_from_parent(swayc_t *parent, swayc_t *container);
|
||||||
swayc_t *create_container(swayc_t *parent, wlc_handle handle);
|
swayc_t *create_container(swayc_t *parent, wlc_handle handle);
|
||||||
|
void free_swayc(swayc_t *container);
|
||||||
swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);
|
swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
list_t *create_list() {
|
list_t *create_list(void) {
|
||||||
list_t *list = malloc(sizeof(list_t));
|
list_t *list = malloc(sizeof(list_t));
|
||||||
list->capacity = 10;
|
list->capacity = 10;
|
||||||
list->length = 0;
|
list->length = 0;
|
||||||
|
|
|
@ -7,7 +7,7 @@ typedef struct {
|
||||||
void **items;
|
void **items;
|
||||||
} list_t;
|
} list_t;
|
||||||
|
|
||||||
list_t *create_list();
|
list_t *create_list(void);
|
||||||
void list_free(list_t *list);
|
void list_free(list_t *list);
|
||||||
void list_add(list_t *list, void *item);
|
void list_add(list_t *list, void *item);
|
||||||
void list_insert(list_t *list, int index, void *item);
|
void list_insert(list_t *list, int index, void *item);
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
swayc_t *active_workspace = NULL;
|
swayc_t *active_workspace = NULL;
|
||||||
|
|
||||||
char *workspace_next_name() {
|
char *workspace_next_name(void) {
|
||||||
return "1";
|
//TODO change this i guess. seems pretty bad
|
||||||
|
char *name = malloc(sizeof("1"));
|
||||||
|
return strcpy(name, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
swayc_t *workspace_create(const char* name) {
|
swayc_t *workspace_create(const char* name) {
|
||||||
|
@ -35,6 +37,17 @@ bool workspace_by_name(swayc_t *view, void *data) {
|
||||||
(strcasecmp(view->name, (char *) data) == 0);
|
(strcasecmp(view->name, (char *) data) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool workspace_destroy(swayc_t *workspace) {
|
||||||
|
//Dont destroy if there are children
|
||||||
|
if (workspace->children->length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
|
||||||
|
free_swayc(workspace);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void set_mask(swayc_t *view, void *data) {
|
void set_mask(swayc_t *view, void *data) {
|
||||||
uint32_t *p = data;
|
uint32_t *p = data;
|
||||||
|
|
||||||
|
@ -49,12 +62,12 @@ swayc_t *workspace_find_by_name(const char* name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void workspace_switch(swayc_t *workspace) {
|
void workspace_switch(swayc_t *workspace) {
|
||||||
if(active_workspace) {
|
if (workspace != active_workspace && active_workspace) {
|
||||||
sway_log(L_DEBUG, "workspace: changing from %s to %s", active_workspace->name, workspace->name);
|
sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", active_workspace->name, workspace->name);
|
||||||
|
|
||||||
uint32_t mask = 1;
|
uint32_t mask = 1;
|
||||||
// set all c_views in the old workspace to the invisible mask
|
// set all c_views in the old workspace to the invisible mask
|
||||||
container_map(active_workspace, set_mask, &mask);
|
container_map(active_workspace, set_mask, &mask);
|
||||||
|
|
||||||
// and c_views in the new workspace to the visible mask
|
// and c_views in the new workspace to the visible mask
|
||||||
mask = 2;
|
mask = 2;
|
||||||
container_map(workspace, set_mask, &mask);
|
container_map(workspace, set_mask, &mask);
|
||||||
|
@ -62,7 +75,7 @@ void workspace_switch(swayc_t *workspace) {
|
||||||
wlc_output_set_mask(wlc_get_focused_output(), 2);
|
wlc_output_set_mask(wlc_get_focused_output(), 2);
|
||||||
unfocus_all(active_workspace);
|
unfocus_all(active_workspace);
|
||||||
focus_view(workspace);
|
focus_view(workspace);
|
||||||
|
workspace_destroy(active_workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
active_workspace = workspace;
|
active_workspace = workspace;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
char *workspace_next_name();
|
char *workspace_next_name(void);
|
||||||
swayc_t *workspace_create(const char*);
|
swayc_t *workspace_create(const char*);
|
||||||
swayc_t *workspace_find_by_name(const char*);
|
swayc_t *workspace_find_by_name(const char*);
|
||||||
void workspace_switch(swayc_t*);
|
void workspace_switch(swayc_t*);
|
||||||
|
|
Loading…
Reference in a new issue