mirror of
https://github.com/NickHu/sway
synced 2024-12-26 21:58:30 +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;
|
||||
}
|
||||
|
||||
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);
|
||||
char *ptr, *cmd;
|
||||
bool exec_success;
|
||||
|
|
|
@ -8,6 +8,6 @@ struct cmd_handler {
|
|||
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
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "config.h"
|
||||
|
||||
bool load_config() {
|
||||
sway_log(L_INFO, "Loading config");
|
||||
// TODO: Allow use of more config file locations
|
||||
const char *name = "/.sway/config";
|
||||
const char *home = getenv("HOME");
|
||||
|
@ -65,7 +66,7 @@ struct sway_config *read_config(FILE *file, bool is_active) {
|
|||
goto _continue;
|
||||
}
|
||||
|
||||
if (!temp_depth && handle_command(config, line) != 0) {
|
||||
if (!temp_depth && handle_command(config, line) != true) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
|
@ -76,7 +77,7 @@ _continue:
|
|||
free(line);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (success == false) {
|
||||
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.layout = L_NONE;
|
||||
root_container.children = create_list();
|
||||
|
@ -128,6 +128,9 @@ void init_layout() {
|
|||
|
||||
void free_swayc(swayc_t *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);
|
||||
if (container->name) {
|
||||
free(container->name);
|
||||
|
|
|
@ -45,7 +45,7 @@ typedef struct sway_container swayc_t;
|
|||
|
||||
extern swayc_t root_container;
|
||||
|
||||
void init_layout();
|
||||
void init_layout(void);
|
||||
void add_child(swayc_t *parent, swayc_t *child);
|
||||
void add_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);
|
||||
int remove_container_from_parent(swayc_t *parent, swayc_t *container);
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
list_t *create_list() {
|
||||
list_t *create_list(void) {
|
||||
list_t *list = malloc(sizeof(list_t));
|
||||
list->capacity = 10;
|
||||
list->length = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ typedef struct {
|
|||
void **items;
|
||||
} list_t;
|
||||
|
||||
list_t *create_list();
|
||||
list_t *create_list(void);
|
||||
void list_free(list_t *list);
|
||||
void list_add(list_t *list, void *item);
|
||||
void list_insert(list_t *list, int index, void *item);
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
swayc_t *active_workspace = NULL;
|
||||
|
||||
char *workspace_next_name() {
|
||||
return "1";
|
||||
char *workspace_next_name(void) {
|
||||
//TODO change this i guess. seems pretty bad
|
||||
char *name = malloc(sizeof("1"));
|
||||
return strcpy(name, "1");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
uint32_t *p = data;
|
||||
|
||||
|
@ -49,12 +62,12 @@ swayc_t *workspace_find_by_name(const char* name) {
|
|||
}
|
||||
|
||||
void workspace_switch(swayc_t *workspace) {
|
||||
if(active_workspace) {
|
||||
sway_log(L_DEBUG, "workspace: changing from %s to %s", active_workspace->name, workspace->name);
|
||||
|
||||
if (workspace != active_workspace && active_workspace) {
|
||||
sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", active_workspace->name, workspace->name);
|
||||
uint32_t mask = 1;
|
||||
// set all c_views in the old workspace to the invisible mask
|
||||
container_map(active_workspace, set_mask, &mask);
|
||||
|
||||
// and c_views in the new workspace to the visible mask
|
||||
mask = 2;
|
||||
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);
|
||||
unfocus_all(active_workspace);
|
||||
focus_view(workspace);
|
||||
workspace_destroy(active_workspace);
|
||||
}
|
||||
|
||||
active_workspace = workspace;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "list.h"
|
||||
#include "layout.h"
|
||||
|
||||
char *workspace_next_name();
|
||||
char *workspace_next_name(void);
|
||||
swayc_t *workspace_create(const char*);
|
||||
swayc_t *workspace_find_by_name(const char*);
|
||||
void workspace_switch(swayc_t*);
|
||||
|
|
Loading…
Reference in a new issue