Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 74e4a77

Browse files
committed
Workaround for focus-at-start bug
1 parent c883bde commit 74e4a77

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

appshell/cefclient_gtk.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
char szWorkingDir[512]; // The current working directory
1919
std:: string szInitialUrl;
2020
std:: string szRunningDir;
21+
int add_handler_id;
2122
bool isReallyClosing = false;
2223

2324
// The global ClientHandler reference.
@@ -33,6 +34,18 @@ void destroy(void) {
3334
void TerminationSignalHandler(int signatl) {
3435
destroy();
3536
}
37+
void HandleAdd(GtkContainer *container,
38+
GtkWidget *widget,
39+
gpointer user_data) {
40+
g_signal_handler_disconnect(container, add_handler_id);
41+
if(gtk_widget_get_can_focus(widget)) {
42+
gtk_widget_grab_focus(widget);
43+
}
44+
else {
45+
add_handler_id = g_signal_connect(G_OBJECT(widget), "add",
46+
G_CALLBACK(HandleAdd), NULL);
47+
}
48+
}
3649

3750
static gboolean HandleQuit(int signatl) {
3851
if (!isReallyClosing && g_handler.get() && g_handler->GetBrowserId()) {
@@ -161,6 +174,8 @@ int main(int argc, char* argv[]) {
161174
G_CALLBACK(HandleQuit), NULL);
162175
g_signal_connect(G_OBJECT(window), "destroy",
163176
G_CALLBACK(gtk_widget_destroyed), &window);
177+
add_handler_id = g_signal_connect(G_OBJECT(window), "add",
178+
G_CALLBACK(HandleAdd), NULL);
164179
// g_signal_connect(G_OBJECT(window), "destroy",
165180
// G_CALLBACK(destroy), NULL);
166181

0 commit comments

Comments
 (0)