diff --git a/src/selectiondialog.cc b/src/selectiondialog.cc index dd3db66..9835667 100644 --- a/src/selectiondialog.cc +++ b/src/selectiondialog.cc @@ -73,6 +73,20 @@ SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr< list_view_text.signal_cursor_changed().connect([this] { cursor_changed(); }); + + window.signal_realize().connect([this] { + Gdk::Rectangle iter_rect; + this->text_view.get_iter_location(this->start_mark->get_iter(), iter_rect); + Gdk::Rectangle visible_rect; + this->text_view.get_visible_rect(visible_rect); + int buffer_x=std::max(iter_rect.get_x(), visible_rect.get_x()); + int buffer_y=iter_rect.get_y()+iter_rect.get_height(); + int window_x, window_y; + this->text_view.buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, buffer_x, buffer_y, window_x, window_y); + int root_x, root_y; + this->text_view.get_window(Gtk::TextWindowType::TEXT_WINDOW_TEXT)->get_root_coords(window_x, window_y, root_x, root_y); + window.move(root_x, root_y+1); //TODO: replace 1 with some margin + }); } void SelectionDialogBase::cursor_changed() { @@ -99,24 +113,7 @@ void SelectionDialogBase::add_row(const std::string& row) { void SelectionDialogBase::show() { shown=true; - - //Move - Gdk::Rectangle iter_rect; - text_view.get_iter_location(start_mark->get_iter(), iter_rect); - Gdk::Rectangle visible_rect; - text_view.get_visible_rect(visible_rect); - int buffer_x=std::max(iter_rect.get_x(), visible_rect.get_x()); - int buffer_y=iter_rect.get_y()+iter_rect.get_height(); - int window_x, window_y; - text_view.buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, buffer_x, buffer_y, window_x, window_y); - int root_x, root_y; - text_view.get_window(Gtk::TextWindowType::TEXT_WINDOW_TEXT)->get_root_coords(window_x, window_y, root_x, root_y); - window.move(root_x, root_y+1); //TODO: replace 1 with some margin - window.show_all(); - //Need to move before and after show all. Some WM's disregards moves before show_all, - //and Wayland does not position correctly unless move is called before show_all - window.move(root_x, root_y+1); if(list_view_text.get_model()->children().size()>0) { if(!list_view_text.get_selection()->get_selected()) { diff --git a/src/tooltips.cc b/src/tooltips.cc index dea87ea..abd4a82 100644 --- a/src/tooltips.cc +++ b/src/tooltips.cc @@ -72,6 +72,10 @@ void Tooltip::show(bool disregard_drawn) { layout->set_text(tooltip_widget->get_buffer()->get_text()); layout->get_pixel_size(size.first, size.second); size.second+=2; + + window->signal_realize().connect([this] { + window->move(position.first, position.second); + }); } //Adjust if tooltip is left of text_view @@ -104,9 +108,8 @@ void Tooltip::show(bool disregard_drawn) { Tooltips::drawn_tooltips_rectangle=rectangle; } - window->move(rectangle.get_x(), rectangle.get_y()); //Added since selectiondialog gets positioned wrong on Wayland unless move is placed before show_all + position={rectangle.get_x(), rectangle.get_y()}; window->show_all(); - window->move(rectangle.get_x(), rectangle.get_y()); //Need both since some VM's disregards moves before show_all } void Tooltip::hide() { diff --git a/src/tooltips.h b/src/tooltips.h index d4a363a..36fbce6 100644 --- a/src/tooltips.h +++ b/src/tooltips.h @@ -24,6 +24,7 @@ private: std::unique_ptr tooltip_widget; Gtk::TextView& text_view; std::pair size; + std::pair position; }; class Tooltips {