view interface

master
Tony Crisci 7 years ago
parent 1156523ccf
commit 0e3eae4baa

@ -99,4 +99,20 @@ struct sway_view {
struct wl_list unmanaged_view_link; // sway_root::unmanaged views
};
const char *view_get_title(struct sway_view *view);
const char *view_get_app_id(struct sway_view *view);
const char *view_get_class(struct sway_view *view);
const char *view_get_instance(struct sway_view *view);
void view_set_size(struct sway_view *view, int width, int height);
void view_set_position(struct sway_view *view, double ox, double oy);
void view_set_activated(struct sway_view *view, bool activated);
void view_close(struct sway_view *view);
#endif

@ -15,8 +15,8 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
struct sway_view *view =
config->handler_context.current_container->sway_view;
if (view && view->iface.close) {
view->iface.close(view);
if (view) {
view_close(view);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);

@ -299,13 +299,8 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
case CRIT_ID: // TODO
break;
case CRIT_APP_ID:
if (!view->iface.get_prop) {
break;
}
const char *app_id =
cont->sway_view->iface.get_prop(view, VIEW_PROP_APP_ID);
{
const char *app_id = view_get_app_id(cont->sway_view);
if (!app_id) {
break;
}
@ -314,6 +309,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
matches++;
}
break;
}
case CRIT_INSTANCE: // TODO
break;
case CRIT_TILING: // TODO

@ -214,7 +214,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
if (container) {
struct sway_view *view = container->sway_view;
view->iface.set_activated(view, true);
view_set_activated(view, true);
wl_signal_add(&container->events.destroy, &seat->focus_destroy);
seat->focus_destroy.notify = handle_focus_destroy;
@ -234,8 +234,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
if (last_focus &&
!sway_input_manager_has_focus(seat->input, last_focus)) {
struct sway_view *view = last_focus->sway_view;
view->iface.set_activated(view, false);
view_set_activated(view, false);
}
}

@ -48,6 +48,7 @@ sway_sources = files(
'security.c',
'tree/container.c',
'tree/layout.c',
'tree/view.c',
'tree/workspace.c',
)

@ -157,7 +157,7 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) {
return NULL;
}
const char *title = sway_view->iface.get_prop(sway_view, VIEW_PROP_TITLE);
const char *title = view_get_title(sway_view);
swayc_t *swayc = new_swayc(C_VIEW);
wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d",
swayc, title, sibling, sibling ? sibling->type : 0);

@ -191,7 +191,7 @@ void arrange_windows(swayc_t *container, double width, double height) {
{
container->width = width;
container->height = height;
container->sway_view->iface.set_size(container->sway_view,
view_set_size(container->sway_view,
container->width, container->height);
wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f",
container->width, container->height,
@ -251,7 +251,7 @@ static void apply_horiz_layout(swayc_t *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, width, scale);
child->sway_view->iface.set_position(child->sway_view, child_x, y);
view_set_position(child->sway_view, child_x, y);
if (i == end - 1) {
double remaining_width = x + width - child_x;
@ -301,7 +301,7 @@ void apply_vert_layout(swayc_t *container,
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, height, scale);
child->sway_view->iface.set_position(child->sway_view, x, child_y);
view_set_position(child->sway_view, x, child_y);
if (i == end - 1) {
double remaining_height = y + height - child_y;

@ -0,0 +1,53 @@
#include "sway/view.h"
const char *view_get_title(struct sway_view *view) {
if (view->iface.get_prop) {
return view->iface.get_prop(view, VIEW_PROP_TITLE);
}
return NULL;
}
const char *view_get_app_id(struct sway_view *view) {
if (view->iface.get_prop) {
return view->iface.get_prop(view, VIEW_PROP_APP_ID);
}
return NULL;
}
const char *view_get_class(struct sway_view *view) {
if (view->iface.get_prop) {
return view->iface.get_prop(view, VIEW_PROP_CLASS);
}
return NULL;
}
const char *view_get_instance(struct sway_view *view) {
if (view->iface.get_prop) {
return view->iface.get_prop(view, VIEW_PROP_INSTANCE);
}
return NULL;
}
void view_set_size(struct sway_view *view, int width, int height) {
if (view->iface.set_size) {
view->iface.set_size(view, width, height);
}
}
void view_set_position(struct sway_view *view, double ox, double oy) {
if (view->iface.set_position) {
view->iface.set_position(view, ox, oy);
}
}
void view_set_activated(struct sway_view *view, bool activated) {
if (view->iface.set_activated) {
view->iface.set_activated(view, activated);
}
}
void view_close(struct sway_view *view) {
if (view->iface.close) {
view->iface.close(view);
}
}
Loading…
Cancel
Save