fixed some more bugs, moved layout_log into log.ch, restored focus_parent

This commit is contained in:
taiyu 2015-08-19 01:06:15 -07:00
parent e16a4015ff
commit c5a6982893
7 changed files with 70 additions and 63 deletions

View file

@ -1,6 +1,7 @@
#ifndef _SWAY_LOG_H #ifndef _SWAY_LOG_H
#define _SWAY_LOG_H #define _SWAY_LOG_H
#include <stdbool.h> #include <stdbool.h>
#include "container.h"
typedef enum { typedef enum {
L_SILENT = 0, L_SILENT = 0,
@ -15,4 +16,5 @@ void sway_log(int verbosity, const char* format, ...) __attribute__((format(prin
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
void layout_log(const swayc_t *c, int depth);
#endif #endif

View file

@ -15,6 +15,5 @@ void workspace_output_next();
void workspace_next(); void workspace_next();
void workspace_output_prev(); void workspace_output_prev();
void workspace_prev(); void workspace_prev();
void layout_log(const swayc_t *c, int depth);
#endif #endif

View file

@ -182,20 +182,22 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
if (view->type != C_VIEW) { if (view->type != C_VIEW) {
return true; return true;
} }
int i;
// Change from nonfloating to floating // Change from nonfloating to floating
if (!view->is_floating) { if (!view->is_floating) {
remove_child(view); //Remove view from its current location
destroy_container(remove_child(view));
//and move it into workspace floating
add_floating(active_workspace,view); add_floating(active_workspace,view);
view->x = (active_workspace->width - view->width)/2; view->x = (active_workspace->width - view->width)/2;
view->y = (active_workspace->height - view->height)/2; view->y = (active_workspace->height - view->height)/2;
arrange_windows(active_workspace, -1, -1);
if (view->desired_width != -1) { if (view->desired_width != -1) {
view->width = view->desired_width; view->width = view->desired_width;
} }
if (view->desired_height != -1) { if (view->desired_height != -1) {
view->height = view->desired_height; view->height = view->desired_height;
} }
arrange_windows(active_workspace, -1, -1);
} else { } else {
// Delete the view from the floating list and unset its is_floating flag // Delete the view from the floating list and unset its is_floating flag
// Using length-1 as the index is safe because the view must be the currently // Using length-1 as the index is safe because the view must be the currently
@ -221,10 +223,10 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
add_sibling(focused, view); add_sibling(focused, view);
} }
// Refocus on the view once its been put back into the layout // Refocus on the view once its been put back into the layout
set_focused_container(view);
arrange_windows(active_workspace, -1, -1); arrange_windows(active_workspace, -1, -1);
return true; return true;
} }
set_focused_container(view);
} }
return true; return true;

View file

@ -261,7 +261,6 @@ swayc_t *destroy_container(swayc_t *container) {
sway_log(L_DEBUG, "Container: Destroying container '%p'", container); sway_log(L_DEBUG, "Container: Destroying container '%p'", container);
swayc_t *parent = container->parent; swayc_t *parent = container->parent;
free_swayc(container); free_swayc(container);
container = parent; container = parent;
} }
return container; return container;

View file

@ -146,6 +146,9 @@ void set_focused_container(swayc_t *c) {
// update container focus from here to root, making necessary changes along // update container focus from here to root, making necessary changes along
// the way // the way
swayc_t *p = c; swayc_t *p = c;
if (p->type != C_OUTPUT && p->type != C_ROOT) {
p->is_focused = true;
}
while (p != &root_container) { while (p != &root_container) {
update_focus(p); update_focus(p);
p = p->parent; p = p->parent;

View file

@ -82,3 +82,62 @@ bool sway_assert(bool condition, const char* format, ...) {
return false; return false;
} }
#include "workspace.h"
/* XXX:DEBUG:XXX */
static void container_log(const swayc_t *c) {
fprintf(stderr, "focus:%c|",
c->is_focused ? 'F' : //Focused
c == active_workspace ? 'W' : //active workspace
c == &root_container ? 'R' : //root
'X');//not any others
fprintf(stderr,"(%p)",c);
fprintf(stderr,"(p:%p)",c->parent);
fprintf(stderr,"(f:%p)",c->focused);
fprintf(stderr,"(h:%ld)",c->handle);
fprintf(stderr,"Type:");
fprintf(stderr,
c->type == C_ROOT ? "Root|" :
c->type == C_OUTPUT ? "Output|" :
c->type == C_WORKSPACE ? "Workspace|" :
c->type == C_CONTAINER ? "Container|" :
c->type == C_VIEW ? "View|" : "Unknown|");
fprintf(stderr,"layout:");
fprintf(stderr,
c->layout == L_NONE ? "NONE|" :
c->layout == L_HORIZ ? "Horiz|":
c->layout == L_VERT ? "Vert|":
c->layout == L_STACKED ? "Stacked|":
c->layout == L_FLOATING ? "Floating|":
"Unknown|");
fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
fprintf(stderr, "wgt:%d|", c->weight);
fprintf(stderr, "name:%.16s|", c->name);
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
}
void layout_log(const swayc_t *c, int depth) {
int i, d;
int e = c->children ? c->children->length : 0;
container_log(c);
if (e) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('-', stderr);
layout_log(c->children->items[i], depth + 1);
}
}
if (c->type == C_WORKSPACE) {
e = c->floating?c->floating->length:0;
if (e) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('=', stderr);
layout_log(c->floating->items[i], depth + 1);
}
}
}
}
/* XXX:DEBUG:XXX */

View file

@ -182,60 +182,3 @@ void workspace_switch(swayc_t *workspace) {
set_focused_container(get_focused_view(workspace)); set_focused_container(get_focused_view(workspace));
arrange_windows(workspace, -1, -1); arrange_windows(workspace, -1, -1);
} }
/* XXX:DEBUG:XXX */
static void container_log(const swayc_t *c) {
fprintf(stderr, "focus:%c|",
c->is_focused ? 'F' : //Focused
c == active_workspace ? 'W' : //active workspace
c == &root_container ? 'R' : //root
'X');//not any others
fprintf(stderr,"(%p)",c);
fprintf(stderr,"(p:%p)",c->parent);
fprintf(stderr,"(f:%p)",c->focused);
fprintf(stderr,"(h:%ld)",c->handle);
fprintf(stderr,"Type:");
fprintf(stderr,
c->type == C_ROOT ? "Root|" :
c->type == C_OUTPUT ? "Output|" :
c->type == C_WORKSPACE ? "Workspace|" :
c->type == C_CONTAINER ? "Container|" :
c->type == C_VIEW ? "View|" : "Unknown|");
fprintf(stderr,"layout:");
fprintf(stderr,
c->layout == L_NONE ? "NONE|" :
c->layout == L_HORIZ ? "Horiz|":
c->layout == L_VERT ? "Vert|":
c->layout == L_STACKED ? "Stacked|":
c->layout == L_FLOATING ? "Floating|":
"Unknown|");
fprintf(stderr, "w:%d|h:%d|", c->width, c->height);
fprintf(stderr, "x:%d|y:%d|", c->x, c->y);
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
fprintf(stderr, "wgt:%d|", c->weight);
fprintf(stderr, "name:%.16s|", c->name);
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
}
void layout_log(const swayc_t *c, int depth) {
int i, d;
int e = c->children ? c->children->length : 0;
container_log(c);
if (e) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('-', stderr);
layout_log(c->children->items[i], depth + 1);
}
}
if (c->type == C_WORKSPACE) {
e = c->floating?c->floating->length:0;
if (e) {
for (i = 0; i < e; ++i) {
fputc('|',stderr);
for (d = 0; d < depth; ++d) fputc('-', stderr);
layout_log(c->floating->items[i], depth + 1);
}
}
}
}
/* XXX:DEBUG:XXX */