Commits

Ryan  committed b0da171

Added support for opening a file select dialog and made the dialog modal

  • Participants
  • Parent commits 10a9c95

Comments (0)

Files changed (3)

File X11/DialogManagerX11.cpp

 #include <string>
 #include <boost/thread.hpp>
 #include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+
+
 
 #include "DialogManagerX11.h"
 #include "BrowserHost.h"
 
 void DialogManagerX11::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
 {
-    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this, win, cb));
+    host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this,false, win, cb));
+}
+
+void DialogManagerX11::OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb)
+{
+	host->ScheduleOnMainThread(boost::shared_ptr<DialogManagerX11>(), boost::bind(&DialogManagerX11::_showFolderDialog, this, true, win, cb));
 }
 
-void DialogManagerX11::_showFolderDialog(FB::PluginWindow* win, const PathCallback& cb)
+Window DialogManagerX11::getActiveWindow()
+{
+	Display* d = XOpenDisplay(NULL);
+	if(d == NULL){
+		return None;
+	}
+	Window w;
+	int revert_to;
+	//printf("getting input focus window ... ");
+	XGetInputFocus(d, &w, &revert_to); // see man
+	if(w == None){
+		return None;
+	}
+
+
+	Window parent = w;
+	Window root = None;
+	Window *children;
+	unsigned int nchildren;
+	Status s;
+
+	//printf("getting top window ... \n");
+	while (parent != root) {
+		w = parent;
+		s = XQueryTree(d, w, &root, &parent, &children, &nchildren); // see man
+
+		if (s)
+			XFree(children);
+	}
+
+	return w;
+}
+
+void DialogManagerX11::_showFolderDialog(bool forFile, FB::PluginWindow* win, const PathCallback& cb)
 {
     std::string out;
     GtkWidget *dialog;
     dialog = gtk_file_chooser_dialog_new ("Open File",
 				      NULL,
-				      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+				      forFile ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 				      NULL);
+    gtk_widget_realize(dialog);
+    GdkWindow* gdk_window = gtk_widget_get_window(dialog);
+    Window w = getActiveWindow();
+    if (w != None)
+    {
+		XSetTransientForHint(GDK_WINDOW_XDISPLAY(gdk_window),
+							   GDK_WINDOW_XID(gdk_window),
+							   w);
+    }
     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
     {
         char *filename;

File X11/DialogManagerX11.h

 
 #include <boost/noncopyable.hpp>
 #include <string>
+#include <X11/Xlib.h>           // `apt-get install libx11-dev`
+#include <X11/Xmu/WinUtil.h>
 
 #include "../DialogManager.h"
 
 {
 public:
     void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
-    void _showFolderDialog(FB::PluginWindow* win, const PathCallback& cb);
+    void OpenFileDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+    void _showFolderDialog(bool forFile, FB::PluginWindow* win, const PathCallback& cb);
     
 protected:
     DialogManagerX11() {};
     ~DialogManagerX11() {};
     friend class DialogManager;
+private:
+    Window getActiveWindow();
 };
 #endif // DialogManagerX11_h__

File X11/projectDef.cmake

 # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
 target_link_libraries(${PROJECT_NAME}
     ${PLUGIN_INTERNAL_DEPS}
+    X11
     )