Skip to content

Commit

Permalink
plugin: Grab keyboard focus when the plugin window is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
aajanki committed Nov 19, 2012
1 parent 9e06cc2 commit ee8fb79
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backends/input.cpp
Expand Up @@ -94,9 +94,13 @@ bool InputThread::worker(GdkEvent *event)
}
case GDK_BUTTON_PRESS:
{
//Grab focus, to receive keypresses
if(event->button.button == 1)
{
//Grab focus, to receive keypresses
engineData->grabFocus();

handleMouseDown(event->button.x,event->button.y);
}
ret=TRUE;
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Expand Up @@ -84,6 +84,11 @@ class StandaloneEngineData: public EngineData
{
return true;
}
void grabFocus()
{
/* Nothing to do because the standalone main window is
* always focused */
}
};

int main(int argc, char* argv[])
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/engineutils.h
Expand Up @@ -78,6 +78,8 @@ class DLL_PUBLIC EngineData
* It fills this->widget and this->window.
*/
void showWindow(uint32_t w, uint32_t h);
/* This function must be called within gdk_threads_enter/leave */
virtual void grabFocus()=0;
static gboolean inputDispatch(GtkWidget *widget, GdkEvent *event, EngineData* e)
{
RecMutex::Lock l(e->mutex);
Expand Down
8 changes: 8 additions & 0 deletions src/plugin/plugin.cpp
Expand Up @@ -482,6 +482,14 @@ GtkWidget* PluginEngineData::createGtkWidget()
}
#endif

void PluginEngineData::grabFocus()
{
if (!widget)
return;

gtk_widget_grab_focus(widget);
}

NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(aWindow == NULL)
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/plugin.h
Expand Up @@ -88,6 +88,8 @@ class PluginEngineData: public EngineData
GdkNativeWindow getWindowForGnash();
/* must be called within the gtk_main() thread and within gdk_threads_enter/leave */
GtkWidget* createGtkWidget();
/* must be called within the gtk_main() thread and within gdk_threads_enter/leave */
void grabFocus();
};

class nsPluginInstance : public nsPluginInstanceBase
Expand Down

0 comments on commit ee8fb79

Please sign in to comment.