You are not logged in.

#1 2008-10-29 17:44:53

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

How can I detect if the user "prefers" Qt or GTK?

It sounds impossible, but I want to try.

I'm thinking that a start might be reading the root window atoms in addition to the process list, but I'm not too sure what else.

This goes beyond "the user's running {KDE,GNOME}"; I don't really want to figure out the windowmanager, I want to use deduction so as to figure out what toolkit the user would prefer something to use. The idea is then to compile both Qt and GTK toolkit calls into whatever given program along with a simple abstraction layer and the detection stuff, so I can from there figure out which toolkit to use at startup.

I don't expect perfect detection, but it'd be fun to figure out.

Ideas, anyone?

My first stab at detecting a "GTK preference" is checking if the user is running gnome-session-manager. I'm not too sure what processes set "KDE session" apart from "a Qt-based program is running" because Qt has this tendancy to load 3874692725 things when anything starts and leave them preloaded for the next app. Nice idea, but not for low-RAM machines like mine. Only reason I haven't ravaged bits of KDE and stuffed them into my openbox desktop configuration tongue

-dav7

Last edited by dav7 (2008-10-29 17:46:03)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#2 2008-10-29 20:00:44

ornitorrincos
Forum Fellow
From: Bilbao, spain
Registered: 2006-11-20
Posts: 198

Re: How can I detect if the user "prefers" Qt or GTK?

why not use qt and let it change the style to be as the DE?
or use gtk and hope that if the user really preffers qt he will have qtk-qt or whatever it's called

apart from curiosity about how to do it, of course


-$: file /dev/zero
/dev/zero: symbolic link to '/dev/brain'

Offline

#3 2008-10-29 21:20:02

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: How can I detect if the user "prefers" Qt or GTK?

That would work, but I'm aiming for more of a generalized, globalized solution.

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#4 2008-10-29 22:25:37

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: How can I detect if the user "prefers" Qt or GTK?

The simplest heuristic that covers most cases would be:

if kde_running() then use_qt() else use_gtk()

Gnome and XFCE of course use GTK, and the vast majority of WM-only or hand-rolled DE setups I've seen use primarily GTK apps when there's a choice.

Offline

#5 2008-10-29 22:53:28

Square
Member
Registered: 2008-06-11
Posts: 435

Re: How can I detect if the user "prefers" Qt or GTK?

Why not a one time startup dialog that asks the question?


 

Offline

#6 2008-10-29 23:01:39

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: How can I detect if the user "prefers" Qt or GTK?

I wouldn't waste the time on implementing both. You're just creating a pain for yourself and a terribly complicated code base.

Pick one and focus on the application itself.

Offline

#7 2008-10-29 23:43:10

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: How can I detect if the user "prefers" Qt or GTK?

Oh I'm not actually focusing on anything in particular at the moment. I'm just getting a feel for C, and doing various and sundry things like writing stuff in pure Xlib, making rendering engines, figuring out how to make an app pack in both Qt and GTK, etc.

lol

-dav7

Last edited by dav7 (2008-10-29 23:43:33)


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#8 2008-11-06 17:52:49

thisperishedmin
Member
Registered: 2008-11-04
Posts: 164

Re: How can I detect if the user "prefers" Qt or GTK?

Square wrote:

Why not a one time startup dialog that asks the question?

I'm not sure if you mean one time as in - one time on the first application launch, or one time as in the first time you launch an app for a session.

If you mean the latter, i would personally be driven insane by it.  A once and down prompt is a relatively nice solution though IMO.  Provided there is an option in settings to revert down the road.

Offline

#9 2008-11-06 20:13:22

Square
Member
Registered: 2008-06-11
Posts: 435

Re: How can I detect if the user "prefers" Qt or GTK?

Well, I would mean the first time and only the first time the app is ran, the user is asked and the preference is stored. This would also provide a means for switching back and forth since the selection would have to be stored somewhere anyhow.


 

Offline

#10 2008-11-06 20:18:24

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,390
Website

Re: How can I detect if the user "prefers" Qt or GTK?

dav7 wrote:

Oh I'm not actually focusing on anything in particular at the moment. I'm just getting a feel for C, and doing various and sundry things like writing stuff in pure Xlib, making rendering engines, figuring out how to make an app pack in both Qt and GTK, etc.

Just pointing out that if you are using C, then it is going to be GTK.  Qt is a C++ beast (AFAIK).  Even with GTK, I would recommend the gtkmm (C++) interface.

Offline

#11 2009-01-05 05:23:28

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: How can I detect if the user "prefers" Qt or GTK?

How about a environmental variable?
You could have something like this is your .bashrc
export MYTOOLKIT=qt
or
export MYTOOLKIT=gtk

Then in your c-program you do something like this:
char *toolkit;
if ((toolkit = getenv("MYTOOLKIT")) == NULL) {
  fprintf(stderr, "-- 'MYTOOLKIT' not defined - required for this application (argv[0])\n");
  exit(1);
}

if (!strcasecmp(toolkit, "qt")) {
; // qt-part
} else if (!strcasecmp(toolkit, "gtk")) {
; // gtk-part
}

edit: forgot a curly brace - duh!

Last edited by perbh (2009-01-05 05:24:47)

Offline

Board footer

Powered by FluxBB