Revert "get/set_userdata stores swayc_t *, fixed memory leak, minor changes."

master
Drew DeVault 9 years ago
parent 76ec9422a6
commit ae536c21d3

@ -31,9 +31,6 @@ static void free_swayc(swayc_t *c) {
}
remove_child(c->parent, c);
}
if (c->name) {
free(c->name);
}
free(c);
}
@ -54,10 +51,8 @@ swayc_t *new_output(wlc_handle handle) {
output->height = size->h;
output->handle = handle;
//link this to handler
wlc_handle_set_user_data(handle, output);
add_child(&root_container, output);
//TODO something with this
int total_width = 0;
container_map(&root_container, add_output_widths, &total_width);
@ -140,8 +135,6 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
view->name = strdup(title);
view->visible = true;
//Link view to handle
wlc_handle_set_user_data(handle, view);
//Case of focused workspace, just create as child of it
if (sibling->type == C_WORKSPACE) {
add_child(sibling, view);

@ -69,7 +69,7 @@ static void handle_output_destroyed(wlc_handle output) {
static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h);
swayc_t *c = wlc_handle_get_user_data(output);
swayc_t *c = get_swayc_for_handle(output, &root_container);
if (!c) return;
c->width = to->w;
c->height = to->h;
@ -77,7 +77,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_
}
static void handle_output_focused(wlc_handle output, bool focus) {
swayc_t *c = wlc_handle_get_user_data(output);
swayc_t *c = get_swayc_for_handle(output, &root_container);
if (!c) return;
if (focus) {
unfocus_all(&root_container);
@ -88,28 +88,28 @@ static void handle_output_focused(wlc_handle output, bool focus) {
static bool handle_view_created(wlc_handle handle) {
swayc_t *focused = get_focused_container(&root_container);
swayc_t *view = new_view(focused, handle);
//Leave unamanaged windows alone
if (view) {
arrange_windows(view->parent, -1, -1);
//Set maximize flag for windows.
//TODO: floating windows have this unset
wlc_view_set_state(handle, WLC_BIT_MAXIMIZED, true);
if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
unfocus_all(&root_container);
focus_view(view);
}
else {
arrange_windows(view->parent, -1, -1);
} else { //Unmanaged view
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
wlc_view_focus(handle);
}
} else {
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
wlc_view_focus(handle);
if (wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) {
unfocus_all(&root_container);
focus_view(focused);
arrange_windows(focused, -1, -1);
}
return true;
}
static void handle_view_destroyed(wlc_handle handle) {
sway_log(L_DEBUG, "Destroying window %d", handle);
swayc_t *view = wlc_handle_get_user_data(handle);
swayc_t *view = get_swayc_for_handle(handle, &root_container);
swayc_t *parent;
swayc_t *focused = get_focused_container(&root_container);

@ -215,10 +215,10 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) {
}
swayc_t *get_focused_container(swayc_t *parent) {
while (parent->focused) {
parent = parent->focused;
}
if (parent->focused == NULL) {
return parent;
}
return get_focused_container(parent->focused);
}
void unfocus_all(swayc_t *container) {

@ -1,10 +1,6 @@
#ifndef _SWAY_LOG_H
#define _SWAY_LOG_H
#ifndef __GNUC__
# define __attribute__(x)
#endif
typedef enum {
L_SILENT = 0,
L_ERROR = 1,
@ -12,10 +8,9 @@ typedef enum {
L_DEBUG = 3,
} log_importance_t;
void init_log(int verbosity);
void sway_log_colors(int mode);
void sway_log(int verbosity, char* format, ...)__attribute__((format (printf,2,3)));
void sway_abort(char* format, ...) __attribute__((format (printf,1,2)));
void sway_log(int verbosity, char* format, ...);
void sway_abort(char* format, ...);
#endif

@ -53,9 +53,8 @@ char *strip_comments(char *str) {
list_t *split_string(const char *str, const char *delims) {
list_t *res = create_list();
int i, j;
int len = strlen(str);
for (i = 0, j = 0; i < len + 1; ++i) {
if (strchr(delims, str[i]) || i == len) {
for (i = 0, j = 0; i < strlen(str) + 1; ++i) {
if (strchr(delims, str[i]) || i == strlen(str)) {
if (i - j == 0) {
continue;
}
@ -64,7 +63,7 @@ list_t *split_string(const char *str, const char *delims) {
left[i - j] = 0;
list_add(res, left);
j = i + 1;
while (j <= len && str[j] && strchr(delims, str[j])) {
while (j <= strlen(str) && str[j] && strchr(delims, str[j])) {
j++;
i++;
}
@ -111,44 +110,40 @@ int unescape_string(char *string) {
for (i = 0; string[i]; ++i) {
if (string[i] == '\\') {
--len;
int shift = 0;
switch (string[++i]) {
case '0':
string[i - 1] = '\0';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'a':
string[i - 1] = '\a';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'b':
string[i - 1] = '\b';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 't':
string[i - 1] = '\t';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'n':
string[i - 1] = '\n';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'v':
string[i - 1] = '\v';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'f':
string[i - 1] = '\f';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
case 'r':
string[i - 1] = '\r';
shift = 1;
memmove(string + i, string + i + 1, len - i);
break;
}
if (shift) {
memmove(string + i, string + i + shift, len - i);
}
}
}
return len;

@ -26,7 +26,7 @@ char *workspace_next_name(void) {
list_t *args = split_string(command, " ");
if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) {
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", (char *)args->items[1]);
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]);
char* target = malloc(strlen(args->items[1]) + 1);
strcpy(target, args->items[1]);
while (*target == ' ' || *target == '\t')

Loading…
Cancel
Save