Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk Sharp within Windows #442

Closed
Hecatron opened this issue Jan 14, 2016 · 7 comments
Closed

Gtk Sharp within Windows #442

Hecatron opened this issue Jan 14, 2016 · 7 comments

Comments

@Hecatron
Copy link

Hi, I've recently been trying out Eto.Forms using different backends under Windows 10 (since I'm looking for a cross platform toolkit).

One things I have noticed when running the Eto.Test.Gtk2
under windows 10 / Visual Studio 2015 / with the latest Gtk Sharp
was the following exception
"Unable to load DLL 'libgtk-win32-2.0-0.dll': The specified procedure could not be found"

This led me to this link https://forums.xamarin.com/discussion/15568/unable-to-load-dll-libgtk-win32-2-0-0-dll

It turns out the fix is to include a function which fixes up most of the issues with the finding of gtk dll's when running under windows
The following seems to fix the problem, although I'm not sure if this is something that needs to be rolled into Eto.Forms or not in some way

namespace Eto.Test.Gtk2
{
    class Startup
    {
        //[STAThread]
        static void Main(string[] args)
        {
            CheckWindowsGtk(); // Fixes GTK library find issues
            var platform = new Eto.GtkSharp.Platform();

            var app = new TestApplication(platform);
            app.TestAssemblies.Add(typeof(Startup).Assembly);
            app.Run();
        }

        static bool CheckWindowsGtk()
        {
            string location = null;
            Version version = null;
            Version minVersion = new Version(2, 12, 22);
            using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\InstallFolder"))
            {
                if (key != null)
                    location = key.GetValue(null) as string;
            }
            using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Xamarin\GtkSharp\Version"))
            {
                if (key != null)
                    Version.TryParse(key.GetValue(null) as string, out version);
            }
            //TODO: check build version of GTK# dlls in GAC
            if (version == null || version < minVersion || location == null || !File.Exists(Path.Combine(location, "bin", "libgtk-win32-2.0-0.dll")))
            {
                Console.WriteLine("Did not find required GTK# installation");
                //  string url = "http://monodevelop.com/Download";
                //  string caption = "Fatal Error";
                //  string message =
                //      "{0} did not find the required version of GTK#. Please click OK to open the download page, where " +
                //      "you can download and install the latest version.";
                //  if (DisplayWindowsOkCancelMessage (
                //      string.Format (message, BrandingService.ApplicationName, url), caption)
                //  ) {
                //      Process.Start (url);
                //  }
                return false;
            }
            Console.WriteLine("Found GTK# version " + version);
            var path = Path.Combine(location, @"bin");
            Console.WriteLine("SetDllDirectory(\"{0}\") ", path);
            try
            {
                if (SetDllDirectory(path))
                {
                    return true;
                }
            }
            catch (EntryPointNotFoundException)
            {
            }
            // this shouldn't happen unless something is weird in Windows
            Console.WriteLine("Unable to set GTK+ dll directory");
            return true;
        }

        [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
        [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
        static extern bool SetDllDirectory(string lpPathName);
    }
}
@cwensley
Copy link
Member

How did you install GTK#? After installing using the package from here (and rebooting), I can run the GTK2 app just fine on Windows 10.

@Hecatron
Copy link
Author

I did the same thing, downloaded from the same link but for whatever reason it didn't find the dll's
I've moved onto GTK3 now anyway. I've discovered that if you install gtksharp from the msi you get the gtk2 version. But if you install GTKSharp via nuget you can get the GTK3 version instead which seems better.

@cwensley
Copy link
Member

Yeah I've seen those unofficial Gtk#3 nuget packages, but haven't tried them yet. GTK3 is definitely the way to go if that works for you.

As for this error, did you get the error when initially running the app, or with one of the tests?

@Hecatron
Copy link
Author

I think it was when initially running the example app, and setting it to use gtk in code. It might just be a paths related issue I'm not sure

@cwensley
Copy link
Member

cwensley commented Feb 3, 2016

It looks like some people have found re-installing GTK# got things working for them.

BTW, I finally tried GTK#3 on windows and it seems to work semi-okay. I'm not sure why, but it appeared as if anti-aliasing was turned off completely.. or perhaps it didn't know what to do with high DPI. Either way, it seems to work at least (;

@Hecatron
Copy link
Author

Hecatron commented Feb 4, 2016

I have a fix for that, it's cairo's default settings which are the problem

If using gtksharp directly

        Public Shared Sub ApplyTheme()
            ' Based on this Link http://awesome.naquadah.org/wiki/Better_Font_Rendering

            ' Get the Global Settings
            Dim setts = Gtk.Settings.Default
            ' This enables clear text on Win32, makes the text look a lot less crappy
            setts.XftRgba = "rgb"
            ' This enlarges the size of the controls based on the dpi
            setts.XftDpi = 96
            ' By Default Anti-aliasing is enabled, if you want to disable it for any reason set this value to 0
            'setts.XftAntialias = 0
            ' Enable text hinting
            setts.XftHinting = 1
            'setts.XftHintstyle = "hintslight"
            setts.XftHintstyle = "hintfull"

            ' Load the Theme
            Dim css_provider As New Gtk.CssProvider
            'css_provider.LoadFromPath("themes/DeLorean-3.14/gtk-3.0/gtk.css")
            css_provider.LoadFromPath("themes/DeLorean-Dark-3.14/gtk-3.0/gtk.css")
            Gtk.StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800)

        End Sub

@cwensley
Copy link
Member

Closing this as it seems to be an installation or environment issue with GTK#2, and it looks like using GTK#3 might be the best way forward instead. Feel free to reopen if you feel it still needs to be addressed within Eto.Forms directly, though I don't feel this is something that Eto.Forms should be doing.

Thanks for submitting the issue and providing a sample, it is very appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants