Fix target uri handling when leaving window

Introduce a new string pointer overtitle in Client to be able to keep
the targeturi intact while modifying the former for overriding or not
the window title.
Connect to GDK_ENTER_NOTIFY to restore overtitle when refocusing on
window.
This commit is contained in:
Quentin Rameau 2015-11-22 16:45:22 +01:00
parent d0020bad4f
commit 971856a579

27
surf.c
View file

@ -70,7 +70,7 @@ typedef struct Client {
GTlsCertificateFlags tlsflags; GTlsCertificateFlags tlsflags;
Window xid; Window xid;
int progress, fullscreen; int progress, fullscreen;
const char *title, *targeturi; const char *title, *overtitle, *targeturi;
const char *needle; const char *needle;
struct Client *next; struct Client *next;
} Client; } Client;
@ -433,7 +433,7 @@ void
updatetitle(Client *c) updatetitle(Client *c)
{ {
char *title; char *title;
const char *name = c->targeturi ? c->targeturi : const char *name = c->overtitle ? c->overtitle :
c->title ? c->title : ""; c->title ? c->title : "";
if (showindicators) { if (showindicators) {
@ -879,22 +879,25 @@ gboolean
winevent(GtkWidget *w, GdkEvent *e, Client *c) winevent(GtkWidget *w, GdkEvent *e, Client *c)
{ {
switch (e->type) { switch (e->type) {
case GDK_LEAVE_NOTIFY: case GDK_ENTER_NOTIFY:
c->targeturi = NULL; c->overtitle = c->targeturi;
updatetitle(c); updatetitle(c);
break; break;
case GDK_WINDOW_STATE: /* fallthrough */ case GDK_LEAVE_NOTIFY:
c->overtitle = NULL;
updatetitle(c);
break;
case GDK_WINDOW_STATE:
if (e->window_state.changed_mask == if (e->window_state.changed_mask ==
GDK_WINDOW_STATE_FULLSCREEN) { GDK_WINDOW_STATE_FULLSCREEN)
c->fullscreen = e->window_state.new_window_state & c->fullscreen = e->window_state.new_window_state &
GDK_WINDOW_STATE_FULLSCREEN; GDK_WINDOW_STATE_FULLSCREEN;
break; break;
}
default: default:
return FALSE; break;
} }
return TRUE; return FALSE;
} }
void void
@ -965,6 +968,8 @@ createwindow(Client *c)
g_signal_connect(G_OBJECT(w), "destroy", g_signal_connect(G_OBJECT(w), "destroy",
G_CALLBACK(destroywin), c); G_CALLBACK(destroywin), c);
g_signal_connect(G_OBJECT(w), "enter-notify-event",
G_CALLBACK(winevent), c);
g_signal_connect(G_OBJECT(w), "leave-notify-event", g_signal_connect(G_OBJECT(w), "leave-notify-event",
G_CALLBACK(winevent), c); G_CALLBACK(winevent), c);
g_signal_connect(G_OBJECT(w), "window-state-event", g_signal_connect(G_OBJECT(w), "window-state-event",
@ -1037,6 +1042,8 @@ mousetargetchanged(WebKitWebView *v, WebKitHitTestResult *h, guint modifiers,
c->targeturi = webkit_hit_test_result_get_media_uri(h); c->targeturi = webkit_hit_test_result_get_media_uri(h);
else else
c->targeturi = NULL; c->targeturi = NULL;
c->overtitle = c->targeturi;
updatetitle(c); updatetitle(c);
} }