Skip to content

Commit

Permalink
Merge pull request #138 from WayfireWM/fix-110-popup-done
Browse files Browse the repository at this point in the history
Fix 110 popup done
  • Loading branch information
ammen99 authored Feb 5, 2019
2 parents c3424b3 + 3100ff4 commit acb5f20
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 32 deletions.
96 changes: 75 additions & 21 deletions src/core/wm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "debug.hpp"
#include "core.hpp"
#include "workspace-manager.hpp"

#include "../view/xdg-shell.hpp"
#include "../view/xdg-shell-v6.hpp"

#include <linux/input.h>
#include "signal-definitions.hpp"

Expand Down Expand Up @@ -41,37 +45,87 @@ void wayfire_focus::init(wayfire_config *)
grab_interface->name = "_wf_focus";
grab_interface->abilities_mask = WF_ABILITY_CHANGE_VIEW_GEOMETRY;

const auto check_focus_view = [=] (wayfire_surface_t *focus)
on_button = [=] (uint32_t button, int x, int y) {
this->check_focus_surface(core->get_cursor_focus());
};
output->add_button(new_static_option("BTN_LEFT"), &on_button);

on_touch = [=] (int x, int y) {
this->check_focus_surface(core->get_touch_focus());
};
output->add_touch(new_static_option(""), &on_touch);

on_view_disappear = [=] (signal_data *data) {
set_last_focus(nullptr);
};

on_view_output_change = [=] (signal_data *data)
{
if (!focus)
return;
if (get_signaled_output(data) != this->output)
send_done(last_focus); // will also reset last_focus
};
}

auto main_surface = focus->get_main_surface();
wayfire_view view = nullptr;
void wayfire_focus::check_focus_surface(wayfire_surface_t* focus)
{
/* Find the main view */
auto main_surface = focus ? focus->get_main_surface() : nullptr;
auto view = main_surface ? core->find_view(main_surface) : nullptr;

if (!main_surface || !(view = core->find_view(main_surface)))
return;
/* Close popups from the lastly focused view */
if (last_focus != view)
send_done(last_focus);

if (!view->is_mapped() || !output->activate_plugin(grab_interface))
return;
if (!view || !view->is_mapped() || !output->activate_plugin(grab_interface))
return;

output->deactivate_plugin(grab_interface);
view->get_output()->focus_view(view);
};
output->deactivate_plugin(grab_interface);
view->get_output()->focus_view(view);
set_last_focus(view);
}

callback = [=] (uint32_t button, int x, int y)
void wayfire_focus::send_done(wayfire_view view)
{
if (!last_focus)
return;

std::vector<wayfire_xdg_popup*> popups;
std::vector<wayfire_xdg6_popup*> popups_v6;

/* Do not send done while running */
last_focus->for_each_surface([&] (wayfire_surface_t* surface, int, int)
{
check_focus_view(core->get_cursor_focus());
};
auto popup = dynamic_cast<wayfire_xdg_popup*> (surface);
auto popup_v6 = dynamic_cast<wayfire_xdg6_popup*> (surface);

output->add_button(new_static_option("BTN_LEFT"), &callback);
touch = [=] (int x, int y)
if (popup)
popups.push_back(popup);
if (popup_v6)
popups_v6.push_back(popup_v6);
});

for (auto popup : popups)
popup->send_done();
for (auto popup : popups_v6)
popup->send_done();

set_last_focus(nullptr);
}

void wayfire_focus::set_last_focus(wayfire_view view)
{
if (last_focus)
{
log_info("got binding");
check_focus_view(core->get_touch_focus());
};
last_focus->disconnect_signal("disappeared", &on_view_disappear);
last_focus->disconnect_signal("set-output", &on_view_output_change);
}

output->add_touch(new_static_option(""), &touch);
last_focus = view;
if (last_focus)
{
last_focus->connect_signal("disappeared", &on_view_disappear);
last_focus->connect_signal("set-output", &on_view_output_change);
}
}

void wayfire_handle_focus_parent::focus_view(wayfire_view view)
Expand Down
12 changes: 10 additions & 2 deletions src/core/wm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ class wayfire_close : public wayfire_plugin_t {
};

class wayfire_focus : public wayfire_plugin_t {
button_callback callback;
touch_callback touch;
button_callback on_button;
touch_callback on_touch;
signal_callback_t on_view_disappear,
on_view_output_change;

wayfire_view last_focus;
void send_done(wayfire_view view);
void set_last_focus(wayfire_view view);
void check_focus_surface(wayfire_surface_t *surface);

public:
void init(wayfire_config*);
};
Expand Down
10 changes: 1 addition & 9 deletions src/view/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void wayfire_view_t::set_minimized(bool minim)
{
view_disappeared_signal data;
data.view = self();
emit_signal("disappear", &data);
emit_signal("disappeared", &data);

output->emit_signal("view-disappeared", &data);
output->workspace->add_view_to_layer(self(), WF_LAYER_MINIMIZED);
Expand Down Expand Up @@ -596,14 +596,6 @@ void wayfire_view_t::activate(bool active)
if (frame)
frame->notify_view_activated(active);

/* we don't send activated or deactivated for shell views,
* they should always be active */
if (role == WF_VIEW_ROLE_SHELL_VIEW)
{
if (!active)
return activate(true);
}

activated = active;
toplevel_send_state();
}
Expand Down
16 changes: 16 additions & 0 deletions src/view/xdg-shell-v6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void wayfire_xdg6_popup::get_child_position(int &x, int &y)
y += popup->geometry.y - popup->base->geometry.y;
}

void wayfire_xdg6_popup::send_done()
{
wlr_xdg_surface_v6_send_close(popup->base);
}

void handle_v6_new_popup(wl_listener*, void *data)
{
auto popup = static_cast<wlr_xdg_popup_v6*> (data);
Expand Down Expand Up @@ -283,6 +288,17 @@ wf_geometry wayfire_xdg6_view::get_wm_geometry()

void wayfire_xdg6_view::activate(bool act)
{
/*
if (!act)
{
for_each_surface([] (wayfire_surface_t* surface, int, int)
{
auto popup = dynamic_cast<wayfire_xdg6_popup*> (surface);
if (popup)
popup->send_done();
});
} */

wlr_xdg_toplevel_v6_set_activated(v6_surface, act);
wayfire_view_t::activate(act);
}
Expand Down
1 change: 1 addition & 0 deletions src/view/xdg-shell-v6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class wayfire_xdg6_popup : public wayfire_surface_t

virtual void get_child_position(int &x, int &y);
virtual bool is_subsurface() { return true; }
virtual void send_done();
};

class wayfire_xdg6_view : public wayfire_view_t
Expand Down
22 changes: 22 additions & 0 deletions src/view/xdg-shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ void wayfire_xdg_popup::get_child_offset(int &x, int &y)
y = popup->base->geometry.y;
}

void wayfire_xdg_popup::send_done()
{
if (is_mapped())
wlr_xdg_popup_destroy(popup->base);
}

void handle_xdg_new_popup(wl_listener*, void *data)
{
auto popup = static_cast<wlr_xdg_popup*> (data);
Expand Down Expand Up @@ -295,6 +301,22 @@ wf_geometry wayfire_xdg_view::get_wm_geometry()

void wayfire_xdg_view::activate(bool act)
{
/*
if (!act)
{
for_each_surface([] (wayfire_surface_t* surface, int, int)
{
auto popup = dynamic_cast<wayfire_xdg_popup*> (surface);
if (popup)
popup->send_done();
});
} */

/* we don't send activated or deactivated for shell views,
* they should always be active */
if (this->role == WF_VIEW_ROLE_SHELL_VIEW)
act = true;

wlr_xdg_toplevel_set_activated(xdg_surface, act);
wayfire_view_t::activate(act);
}
Expand Down
1 change: 1 addition & 0 deletions src/view/xdg-shell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class wayfire_xdg_popup : public wayfire_surface_t
virtual void get_child_offset(int &x, int &y);

virtual bool is_subsurface() { return true; }
virtual void send_done();
};

void handle_xdg_new_popup(wl_listener*, void*);
Expand Down

0 comments on commit acb5f20

Please sign in to comment.