mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 09:44:24 +03:00
GTK: Add transient popup behaviour for local history too
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
parent
d2e5446bfb
commit
a98003674b
@ -35,6 +35,7 @@
|
||||
#include "gtk/resources.h"
|
||||
#include "gtk/corewindow.h"
|
||||
#include "gtk/local_history.h"
|
||||
#include "gtk/scaffolding.h"
|
||||
|
||||
struct nsgtk_local_history_window {
|
||||
struct nsgtk_corewindow core;
|
||||
@ -158,6 +159,12 @@ nsgtk_local_history_init(struct browser_window *bw,
|
||||
ncwin->wnd = GTK_WINDOW(gtk_builder_get_object(ncwin->builder,
|
||||
"wndHistory"));
|
||||
|
||||
/* Configure for transient behaviour */
|
||||
gtk_window_set_type_hint(GTK_WINDOW(ncwin->wnd),
|
||||
GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
|
||||
gtk_window_set_modal(GTK_WINDOW(ncwin->wnd), TRUE);
|
||||
|
||||
|
||||
ncwin->core.scrolled = GTK_SCROLLED_WINDOW(
|
||||
gtk_builder_get_object(ncwin->builder,
|
||||
"HistoryScrolled"));
|
||||
@ -171,6 +178,16 @@ nsgtk_local_history_init(struct browser_window *bw,
|
||||
"delete_event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete),
|
||||
NULL);
|
||||
/* Ditto if we lose the grab */
|
||||
g_signal_connect(G_OBJECT(ncwin->wnd),
|
||||
"grab-broken-event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete),
|
||||
ncwin);
|
||||
/* Handle button press events */
|
||||
g_signal_connect(G_OBJECT(ncwin->wnd),
|
||||
"button-press-event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete),
|
||||
ncwin);
|
||||
|
||||
ncwin->core.draw = nsgtk_local_history_draw;
|
||||
ncwin->core.key = nsgtk_local_history_key;
|
||||
@ -206,7 +223,11 @@ nserror nsgtk_local_history_present(GtkWindow *parent,
|
||||
int width, height;
|
||||
res = nsgtk_local_history_init(bw, &local_history_window);
|
||||
if (res == NSERROR_OK) {
|
||||
gtk_window_group_add_window(gtk_window_get_group(parent),
|
||||
local_history_window->wnd);
|
||||
gtk_window_set_transient_for(local_history_window->wnd, parent);
|
||||
gtk_window_set_screen(local_history_window->wnd,
|
||||
gtk_widget_get_screen(GTK_WIDGET(parent)));
|
||||
|
||||
gtk_window_get_size(parent, &prnt_width, &prnt_height);
|
||||
|
||||
@ -224,7 +245,11 @@ nserror nsgtk_local_history_present(GtkWindow *parent,
|
||||
}
|
||||
gtk_window_resize(local_history_window->wnd, width, height);
|
||||
|
||||
gtk_window_present(local_history_window->wnd);
|
||||
/* Attempt to place the window in the right place */
|
||||
nsgtk_scaffolding_position_local_history(nsgtk_current_scaffolding());
|
||||
|
||||
gtk_widget_show(GTK_WIDGET(local_history_window->wnd));
|
||||
gtk_widget_grab_focus(GTK_WIDGET(local_history_window->wnd));
|
||||
|
||||
local_history_scroll_to_cursor(local_history_window->session);
|
||||
}
|
||||
@ -269,3 +294,11 @@ nserror nsgtk_local_history_destroy(void)
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
/* exported function documented gtk/history.h */
|
||||
void nsgtk_local_history_set_position(int x, int y)
|
||||
{
|
||||
NSLOG(netsurf, INFO, "x=%d y=%d", x, y);
|
||||
|
||||
gtk_window_move(local_history_window->wnd, x, y);
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ struct browser_window;
|
||||
*/
|
||||
nserror nsgtk_local_history_present(GtkWindow *parent, struct browser_window *bw);
|
||||
|
||||
/**
|
||||
* set the local history window position.
|
||||
*/
|
||||
void nsgtk_local_history_set_position(int x, int y);
|
||||
|
||||
/**
|
||||
* hide the local history window from being visible.
|
||||
*
|
||||
|
@ -2,6 +2,7 @@
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 3.0 -->
|
||||
<object class="GtkWindow" id="wndHistory">
|
||||
<property name="type">GTK_WINDOW_POPUP</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">NetSurf Local History</property>
|
||||
<property name="window_position">center</property>
|
||||
|
@ -2,6 +2,7 @@
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 3.0 -->
|
||||
<object class="GtkWindow" id="wndHistory">
|
||||
<property name="type">GTK_WINDOW_POPUP</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">NetSurf Local History</property>
|
||||
<property name="window_position">center</property>
|
||||
|
@ -1581,3 +1581,9 @@ nserror nsgtk_scaffolding_position_page_info(struct nsgtk_scaffolding *gs,
|
||||
{
|
||||
return nsgtk_window_position_page_info(gs->top_level, win);
|
||||
}
|
||||
|
||||
/* exported interface documented in gtk/scaffolding.h */
|
||||
nserror nsgtk_scaffolding_position_local_history(struct nsgtk_scaffolding *gs)
|
||||
{
|
||||
return nsgtk_window_position_local_history(gs->top_level);
|
||||
}
|
||||
|
@ -65,6 +65,13 @@ nserror nsgtk_scaffolding_toolbar_context_menu(struct nsgtk_scaffolding *gs);
|
||||
nserror nsgtk_scaffolding_position_page_info(struct nsgtk_scaffolding *gs,
|
||||
struct nsgtk_pi_window *win);
|
||||
|
||||
/**
|
||||
* Position the local-history popup in the right place
|
||||
*
|
||||
* \param gs The scaffolding to position relative to
|
||||
*/
|
||||
nserror nsgtk_scaffolding_position_local_history(struct nsgtk_scaffolding *gs);
|
||||
|
||||
/**
|
||||
* open the burger menu
|
||||
*/
|
||||
|
@ -3800,15 +3800,34 @@ nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* exported interface documented in toolbar.h */
|
||||
nserror nsgtk_toolbar_position_page_info(struct nsgtk_toolbar *tb,
|
||||
struct nsgtk_pi_window *win)
|
||||
/**
|
||||
* Find the correct location for popping up a window for the chosen item.
|
||||
*
|
||||
* \param tb The toolbar to select from
|
||||
* \param item_idx The toolbar item to select from
|
||||
* \param out_x Filled with an appropriate X coordinate
|
||||
* \param out_y Filled with an appropriate Y coordinate
|
||||
*/
|
||||
static nserror
|
||||
nsgtk_toolbar_get_icon_window_position(struct nsgtk_toolbar *tb,
|
||||
int item_idx,
|
||||
int *out_x,
|
||||
int *out_y)
|
||||
{
|
||||
struct nsgtk_toolbar_item *item = &tb->items[URL_BAR_ITEM];
|
||||
GtkWidget *widget = GTK_WIDGET(gtk_bin_get_child(GTK_BIN(item->button)));
|
||||
struct nsgtk_toolbar_item *item = &tb->items[item_idx];
|
||||
GtkWidget *widget = GTK_WIDGET(item->button);
|
||||
GtkAllocation alloc;
|
||||
gint rootx, rooty, x, y;
|
||||
|
||||
switch (item_idx) {
|
||||
case URL_BAR_ITEM:
|
||||
widget = GTK_WIDGET(gtk_bin_get_child(GTK_BIN(item->button)));
|
||||
break;
|
||||
default:
|
||||
/* Nothing to do here */
|
||||
break;
|
||||
}
|
||||
|
||||
nsgtk_widget_get_allocation(widget, &alloc);
|
||||
|
||||
if (gtk_widget_translate_coordinates(widget,
|
||||
@ -3822,7 +3841,40 @@ nserror nsgtk_toolbar_position_page_info(struct nsgtk_toolbar *tb,
|
||||
gtk_window_get_position(GTK_WINDOW(gtk_widget_get_toplevel(widget)),
|
||||
&rootx, &rooty);
|
||||
|
||||
nsgtk_page_info_set_position(win, rootx + x + 4, rooty + y + 4);
|
||||
*out_x = rootx + x + 4;
|
||||
*out_y = rooty + y + 4;
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
nserror nsgtk_toolbar_position_page_info(struct nsgtk_toolbar *tb,
|
||||
struct nsgtk_pi_window *win)
|
||||
{
|
||||
nserror res;
|
||||
int x, y;
|
||||
|
||||
res = nsgtk_toolbar_get_icon_window_position(tb, URL_BAR_ITEM, &x, &y);
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
|
||||
nsgtk_page_info_set_position(win, x, y);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
/* exported interface documented in toolbar.h */
|
||||
nserror nsgtk_toolbar_position_local_history(struct nsgtk_toolbar *tb)
|
||||
{
|
||||
nserror res;
|
||||
int x, y;
|
||||
|
||||
res = nsgtk_toolbar_get_icon_window_position(tb, HISTORY_BUTTON, &x, &y);
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
|
||||
nsgtk_local_history_set_position(x, y);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
@ -126,6 +126,12 @@ nserror nsgtk_toolbar_show(struct nsgtk_toolbar *tb, bool show);
|
||||
nserror nsgtk_toolbar_position_page_info(struct nsgtk_toolbar *tb,
|
||||
struct nsgtk_pi_window *win);
|
||||
|
||||
/**
|
||||
* position the local history window appropriately
|
||||
*
|
||||
* \param tb The toolbar to position relative to
|
||||
*/
|
||||
nserror nsgtk_toolbar_position_local_history(struct nsgtk_toolbar *tb);
|
||||
|
||||
/**
|
||||
* Initialise customization of toolbar entries
|
||||
|
@ -1684,3 +1684,9 @@ nserror nsgtk_window_position_page_info(struct gui_window *gw,
|
||||
{
|
||||
return nsgtk_toolbar_position_page_info(gw->toolbar, win);
|
||||
}
|
||||
|
||||
/* exported interface documented in window.h */
|
||||
nserror nsgtk_window_position_local_history(struct gui_window *gw)
|
||||
{
|
||||
return nsgtk_toolbar_position_local_history(gw->toolbar);
|
||||
}
|
||||
|
@ -106,4 +106,11 @@ nserror nsgtk_window_item_activate(struct gui_window *gw, nsgtk_toolbar_button i
|
||||
nserror nsgtk_window_position_page_info(struct gui_window *gw,
|
||||
struct nsgtk_pi_window *win);
|
||||
|
||||
/**
|
||||
* position local_history appropriately
|
||||
*
|
||||
* \param gw The gui window handle to position relative to
|
||||
*/
|
||||
nserror nsgtk_window_position_local_history(struct gui_window *gw);
|
||||
|
||||
#endif /* NETSURF_GTK_WINDOW_H */
|
||||
|
Loading…
Reference in New Issue
Block a user