gtk_init_with_args behavior

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

gtk_init_with_args behavior

Allin Cottrell
I'm building an application using gtk-2.24.32 for use on MS Windows,
and have run into a problem which may be associated with my call to
gtk_init_with_args().

I wonder whether, besides handling the arguments detailed in the
(GOptionEntry *) argument to this function, gtk "translates" in some
way the remaining program arguments? If so, this can be problematic.

Here's the case in point: a Greek Windows user, running Windows in
Engish, has named a Desktop subdirectory "test" in Greek (that is,
tau-epsilon-sigma-tau). In the Windows file manager he selects a
file in this subdirectory that's associated via the registry with my
program and double-clicks on it. What my program actually gets as a
residual argument, after calling gtk_init_with_args(), is the full
path to this file, but with the Greek-letter sequence replaced by
"test" -- and therefore, of course, the file cannot be opened.

I'm not sure if it's Windows itself that is making this substitution
or gtk. I'd be grateful if anyone could shed any light on the
matter.

--
Allin Cottrell
Department of Economics
Wake Forest University
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Miroslav Rajcic-2
Hi Allin,

on Windows, it is advisable to use an API to get the command line
parameters as UTF-16,  so you don't lose the letters "foreign" to your
code page.

See "CommandLineToArgvW" for more info:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx

Regards,

   Miroslav

On 5/19/2018 12:06 AM, Allin Cottrell wrote:

> I'm building an application using gtk-2.24.32 for use on MS Windows,
> and have run into a problem which may be associated with my call to
> gtk_init_with_args().
>
> I wonder whether, besides handling the arguments detailed in the
> (GOptionEntry *) argument to this function, gtk "translates" in some
> way the remaining program arguments? If so, this can be problematic.
>
> Here's the case in point: a Greek Windows user, running Windows in
> Engish, has named a Desktop subdirectory "test" in Greek (that is,
> tau-epsilon-sigma-tau). In the Windows file manager he selects a file
> in this subdirectory that's associated via the registry with my
> program and double-clicks on it. What my program actually gets as a
> residual argument, after calling gtk_init_with_args(), is the full
> path to this file, but with the Greek-letter sequence replaced by
> "test" -- and therefore, of course, the file cannot be opened.
>
> I'm not sure if it's Windows itself that is making this substitution
> or gtk. I'd be grateful if anyone could shed any light on the matter.
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Allin Cottrell
On Sat, 19 May 2018, Miroslav Rajcic wrote:

> Hi Allin,
>
> on Windows, it is advisable to use an API to get the command line parameters
> as UTF-16, so you don't lose the letters "foreign" to your code page.
>
> See "CommandLineToArgvW" for more info:

Thanks, Miroslav, that sounds like what I need. Is there such a
thing as a standard way to hook this up with gtk_init_with_args?

I can imagine calling GetCommandLineW, then CommandLineToArgvW, but
then? If you converted the UTF-16 strings to UTF-8, could you then
pass the array to gtk_init_with_args?

Allin Cottrell

> On 5/19/2018 12:06 AM, Allin Cottrell wrote:
>> I'm building an application using gtk-2.24.32 for use on MS Windows, and
>> have run into a problem which may be associated with my call to
>> gtk_init_with_args().
>>
>> I wonder whether, besides handling the arguments detailed in the
>> (GOptionEntry *) argument to this function, gtk "translates" in some way
>> the remaining program arguments? If so, this can be problematic.
>>
>> Here's the case in point: a Greek Windows user, running Windows in Engish,
>> has named a Desktop subdirectory "test" in Greek (that is,
>> tau-epsilon-sigma-tau). In the Windows file manager he selects a file in
>> this subdirectory that's associated via the registry with my program and
>> double-clicks on it. What my program actually gets as a residual argument,
>> after calling gtk_init_with_args(), is the full path to this file, but with
>> the Greek-letter sequence replaced by "test" -- and therefore, of course,
>> the file cannot be opened.
>>
>> I'm not sure if it's Windows itself that is making this substitution or
>> gtk. I'd be grateful if anyone could shed any light on the matter.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Lucky B.C
Well converting from UTF-16 to UTF-8, if you think it must be done.

On Sat, May 19, 2018 at 10:41 PM, Allin Cottrell <[hidden email]> wrote:

> On Sat, 19 May 2018, Miroslav Rajcic wrote:
>
> Hi Allin,
>>
>> on Windows, it is advisable to use an API to get the command line
>> parameters as UTF-16, so you don't lose the letters "foreign" to your code
>> page.
>>
>> See "CommandLineToArgvW" for more info:
>>
>
> Thanks, Miroslav, that sounds like what I need. Is there such a thing as a
> standard way to hook this up with gtk_init_with_args?
>
> I can imagine calling GetCommandLineW, then CommandLineToArgvW, but then?
> If you converted the UTF-16 strings to UTF-8, could you then pass the array
> to gtk_init_with_args?
>
> Allin Cottrell
>
>
> On 5/19/2018 12:06 AM, Allin Cottrell wrote:
>>
>>> I'm building an application using gtk-2.24.32 for use on MS Windows, and
>>> have run into a problem which may be associated with my call to
>>> gtk_init_with_args().
>>>
>>> I wonder whether, besides handling the arguments detailed in the
>>> (GOptionEntry *) argument to this function, gtk "translates" in some way
>>> the remaining program arguments? If so, this can be problematic.
>>>
>>> Here's the case in point: a Greek Windows user, running Windows in
>>> Engish, has named a Desktop subdirectory "test" in Greek (that is,
>>> tau-epsilon-sigma-tau). In the Windows file manager he selects a file in
>>> this subdirectory that's associated via the registry with my program and
>>> double-clicks on it. What my program actually gets as a residual argument,
>>> after calling gtk_init_with_args(), is the full path to this file, but with
>>> the Greek-letter sequence replaced by "test" -- and therefore, of course,
>>> the file cannot be opened.
>>>
>>> I'm not sure if it's Windows itself that is making this substitution or
>>> gtk. I'd be grateful if anyone could shed any light on the matter.
>>>
>> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Miroslav Rajcic-2
I've been doing it exactly like that in my own program, first getting
the UTF-16 from Windows API, then converting to UTF-8 using g_utf16_to_utf8.

IMO, hooking this with gtk_init_with_args is not needed, GTK can use the
standard args of the program, passed via "main()" function parameters,

but you will bypass that mechanism completely and use API to fetch
UTF-16 process parameters directly from OS.

Regards,

   Miroslav

On 5/20/2018 12:36 PM, Lucky B.C wrote:

> Well converting from UTF-16 to UTF-8, if you think it must be done.
>
> On Sat, May 19, 2018 at 10:41 PM, Allin Cottrell <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     On Sat, 19 May 2018, Miroslav Rajcic wrote:
>
>         Hi Allin,
>
>         on Windows, it is advisable to use an API to get the command
>         line parameters as UTF-16, so you don't lose the letters
>         "foreign" to your code page.
>
>         See "CommandLineToArgvW" for more info:
>
>
>     Thanks, Miroslav, that sounds like what I need. Is there such a
>     thing as a standard way to hook this up with gtk_init_with_args?
>
>     I can imagine calling GetCommandLineW, then CommandLineToArgvW,
>     but then? If you converted the UTF-16 strings to UTF-8, could you
>     then pass the array to gtk_init_with_args?
>
>     Allin Cottrell
>
>
>         On 5/19/2018 12:06 AM, Allin Cottrell wrote:
>
>             I'm building an application using gtk-2.24.32 for use on
>             MS Windows, and have run into a problem which may be
>             associated with my call to
>             gtk_init_with_args().
>
>             I wonder whether, besides handling the arguments detailed
>             in the
>             (GOptionEntry *) argument to this function, gtk
>             "translates" in some way the remaining program arguments?
>             If so, this can be problematic.
>
>             Here's the case in point: a Greek Windows user, running
>             Windows in Engish, has named a Desktop subdirectory "test"
>             in Greek (that is, tau-epsilon-sigma-tau). In the Windows
>             file manager he selects a file in this subdirectory that's
>             associated via the registry with my program and
>             double-clicks on it. What my program actually gets as a
>             residual argument, after calling gtk_init_with_args(), is
>             the full path to this file, but with the Greek-letter
>             sequence replaced by "test" -- and therefore, of course,
>             the file cannot be opened.
>
>             I'm not sure if it's Windows itself that is making this
>             substitution or gtk. I'd be grateful if anyone could shed
>             any light on the matter.
>
>     _______________________________________________
>     gtk-app-devel-list mailing list
>     [hidden email] <mailto:[hidden email]>
>     https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>     <https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list>
>
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Allin Cottrell
On Sun, 20 May 2018, Miroslav Rajcic wrote:

> I've been doing it exactly like that in my own program, first getting the
> UTF-16 from Windows API, then converting to UTF-8 using g_utf16_to_utf8.

Thanks, I've now been able to confirm for myself that that works
fine.

> IMO, hooking this with gtk_init_with_args is not needed, GTK can use the
> standard args of the program, passed via "main()" function parameters,
> but you will bypass that mechanism completely and use API to fetch UTF-16
> process parameters directly from OS.

gtk_init_with_args is still useful in my case: it automatically
screens out any command-line arguments that are just option flags or
parameters, via the GOptionEntry mechanism, leaving only a filename
argument to which my program has to respond (but which may be broken
in plain argv). Fortunately, it works fine after conversion via
g_utf16_to_utf8. So my workflow is:

GetCommandLineW
CommandLineToArgvW
convert array of UTF-16 strings to UTF-8
pass the converted array to gtk_init_with_args

Allin Cottrell

ref:
https://mail.gnome.org/archives/gtk-app-devel-list/2018-May/msg00052.html
and following
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

tito-wolit


On 21/05/2018 01:27, Allin Cottrell wrote:

> On Sun, 20 May 2018, Miroslav Rajcic wrote:
>
>> I've been doing it exactly like that in my own program, first getting
>> the UTF-16 from Windows API, then converting to UTF-8 using
>> g_utf16_to_utf8.
>
> Thanks, I've now been able to confirm for myself that that works fine.
>
>> IMO, hooking this with gtk_init_with_args is not needed, GTK can use
>> the standard args of the program, passed via "main()" function
>> parameters,
>> but you will bypass that mechanism completely and use API to fetch
>> UTF-16 process parameters directly from OS.
>
> gtk_init_with_args is still useful in my case: it automatically screens
> out any command-line arguments that are just option flags or parameters,
> via the GOptionEntry mechanism, leaving only a filename argument to
> which my program has to respond (but which may be broken in plain argv).
> Fortunately, it works fine after conversion via g_utf16_to_utf8. So my
> workflow is:
>
> GetCommandLineW
> CommandLineToArgvW
> convert array of UTF-16 strings to UTF-8
> pass the converted array to gtk_init_with_args

Hi,
I use:

filename = g_locale_to_utf8((argv*), -1, NULL, NULL, NULL);
do something with filename
free(filename)

This works also on windows.

Ciao,
Tito

>
> Allin Cottrell
>
> ref:
> https://mail.gnome.org/archives/gtk-app-devel-list/2018-May/msg00052.html
> and following
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Allin Cottrell
On Mon, 21 May 2018, tito-wolit wrote:

> On 21/05/2018 01:27, Allin Cottrell wrote:
>>
>> gtk_init_with_args is still useful in my case: it automatically screens out
>> any command-line arguments that are just option flags or parameters, via
>> the GOptionEntry mechanism, leaving only a filename argument to which my
>> program has to respond (but which may be broken in plain argv).
>> Fortunately, it works fine after conversion via g_utf16_to_utf8. So my
>> workflow is:
>>
>> GetCommandLineW
>> CommandLineToArgvW
>> convert array of UTF-16 strings to UTF-8
>> pass the converted array to gtk_init_with_args
>
> Hi,
> I use:
>
> filename = g_locale_to_utf8((argv*), -1, NULL, NULL, NULL);
> do something with filename
> free(filename)
>
> This works also on windows.

Ah, but it does NOT work in the case I'm talking about, where the
filename in question is not representable in the current Windows
Code Page, because it contains a mixture of character sets. Then the
only way to get the real, non-mangled filename from Windows is in
UTF-16 form via GetCommandLineW.

The problem arises only because Windows doesn't do UTF-8, and so
cannot pass "exotic" filenames via C's argv.

Allin Cottrell


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_init_with_args behavior

Lucky B.C
You should make another version for only Windows, I think that it's better!

On Mon, May 21, 2018 at 6:21 PM, Allin Cottrell <[hidden email]> wrote:

> On Mon, 21 May 2018, tito-wolit wrote:
>
> On 21/05/2018 01:27, Allin Cottrell wrote:
>>
>>>
>>> gtk_init_with_args is still useful in my case: it automatically screens
>>> out any command-line arguments that are just option flags or parameters,
>>> via the GOptionEntry mechanism, leaving only a filename argument to which
>>> my program has to respond (but which may be broken in plain argv).
>>> Fortunately, it works fine after conversion via g_utf16_to_utf8. So my
>>> workflow is:
>>>
>>> GetCommandLineW
>>> CommandLineToArgvW
>>> convert array of UTF-16 strings to UTF-8
>>> pass the converted array to gtk_init_with_args
>>>
>>
>> Hi,
>> I use:
>>
>> filename = g_locale_to_utf8((argv*), -1, NULL, NULL, NULL);
>> do something with filename
>> free(filename)
>>
>> This works also on windows.
>>
>
> Ah, but it does NOT work in the case I'm talking about, where the filename
> in question is not representable in the current Windows Code Page, because
> it contains a mixture of character sets. Then the only way to get the real,
> non-mangled filename from Windows is in UTF-16 form via GetCommandLineW.
>
> The problem arises only because Windows doesn't do UTF-8, and so cannot
> pass "exotic" filenames via C's argv.
>
> Allin Cottrell
>
>
>
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list