Reply
Thread Tools
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#21
Originally Posted by jstokes View Post
Hi,

I've come back to this after a while, sorry for abandoning the thread!

I've only tested this in Scratchbox (strace etc. on personalisation_app worked wonders ), but hopefully, it should work for refreshing the theme. If it doesn't work, you may have to switch to another theme because the underlying components realise that you're reapplying the same theme; if that's the case, I don't know what to do

PHP Code:
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <X11/Xatom.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>

struct _theme_info
{
    
gchar *base_path;
    
gchar *theme_name;
};

static 
gboolean current_theme_info (struct _theme_info *theme_info)
{
    
#define THEME_DIR "/etc/hildon/theme"
    #define INDEX_THEME_FILE G_DIR_SEPARATOR_S "index.theme"
    #define STD_INDEX_LOC THEME_DIR INDEX_THEME_FILE

    
gboolean retval FALSE;
    
gchar *linkdest1 NULL, *linkdest2 NULL;
    
GKeyFile *theme_key g_key_file_new();

    if ((!
g_file_test (STD_INDEX_LOCG_FILE_TEST_EXISTS)) || (!g_key_file_load_from_file (theme_keySTD_INDEX_LOCG_KEY_FILE_NONENULL)) || !(theme_info->theme_name g_key_file_get_string (theme_key"Desktop Entry""Name"NULL)))
        goto 
getout;

    
linkdest1 g_file_read_link (THEME_DIRNULL);
    if (!
linkdest1) goto getout;

    
linkdest2 g_file_read_link (linkdest1NULL); /* Is it a folder that's symlinked to another, like: default->alpha? */
    
theme_info->base_path g_path_get_basename (linkdest2 linkdest2 linkdest1);

    
retval theme_info->base_path != NULL;

getout:
    
g_free (linkdest2);
    
g_free (linkdest1);
    
g_key_file_free (theme_key);

    return 
retval;

#undef STD_INDEX_LOC
#undef INDEX_THEME_FILE
#undef THEME_DIR
}

static 
gboolean update_symbolic_link (const gchar *newtheme)
{
    
gboolean retval FALSE;

    if (
newtheme)
    {
        
gint exit_status;
        
gchar *cmdline;

        
cmdline g_strdup_printf ("%s %s/%s""/usr/bin/personalisation""/usr/share/themes"newtheme);
        
retval g_spawn_command_line_sync (cmdlineNULLNULL, &exit_statusNULL) || exit_status != 0;
        
g_free (cmdline);
    }
    
    return 
retval;
}

static 
void send_refresh_signal (void)
{
    
GdkEventClient event;

    
event.type GDK_CLIENT_EVENT;
    
event.send_event TRUE;
    
event.window NULL;
    
event.message_type gdk_atom_intern ("_GTK_READ_RCFILES"FALSE);
    
event.data_format 8;

    
gdk_event_send_clientmessage_toall ((GdkEvent *) &event);
}

static 
void refresh_matchbox (const gchar *base_path)
{
    
Display *disp XOpenDisplay (getenv ("DISPLAY"));
    
Atom _MB_THEME XInternAtom (disp"_MB_THEME"False);

    if (
_MB_THEME != None)
    {
        
Window root DefaultRootWindow(disp);
        
XChangeProperty (disproot_MB_THEMEXA_STRING8PropModeReplace, (unsigned char*) base_pathstrlen (base_path));

        
Atom _MB_COMMAND XInternAtom (disp"_MB_COMMAND"False);
        if (
_MB_COMMAND != None)
        {
            
XEvent ev = { '\0', };

            
ev.xclient.type ClientMessage;
            
ev.xclient.window root;
            
ev.xclient.message_type _MB_COMMAND;
            
ev.xclient.format 8;
            
ev.xclient.data.l[0] = 1;
            
            
XSendEvent(disprootFalseSubstructureRedirectMask|SubstructureNotifyMask, &ev);
        }
        
        
XSync (dispTrue);
    }
    
    
XCloseDisplay (disp);
}

int main (int argcchar *argv[])
{
    
struct _theme_info theme_info;
    
gtk_init (&argc, &argv);
    
    
g_assert (current_theme_info(&theme_info));

    if (!
update_symbolic_link (theme_info.base_path))
        return 
1/* Fails in my SB - "invalid cross-device link */

    
GtkSettings *settings gtk_settings_get_default();
    
gtk_settings_set_string_property (settings"gtk-theme-name"theme_info.theme_namebasename(argv[0]));
    
//g_object_notify (G_OBJECT (settings), "gtk-theme-name");
    
gtk_rc_reset_styles (settings);

    
send_refresh_signal();

    
gchar *maemo_launcher_pid_s;
    if (
g_file_get_contents ("/tmp/maemo-launcher.pid", &maemo_launcher_pid_sNULLNULL))
    {
        
pid_t maemo_launcher_pid = (pid_tatoi (maemo_launcher_pid_s);
        if (
maemo_launcher_pid 0kill (maemo_launcher_pidSIGHUP);
        
g_free (maemo_launcher_pid_s);
    }
    
    
refresh_matchbox (theme_info.base_path);

    
g_free (theme_info.base_path);
    
g_free (theme_info.theme_name);

    return 
0;

Just using gtk+-2.0 for pkg-config works to compile it
Thanks! Could you please do me one more favour since I'm pretty n00b with compiling non-qt stuff; how do I compile this in scratchbox?
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#22
Originally Posted by d-iivil View Post
Thanks! Could you please do me one more favour since I'm pretty n00b with compiling non-qt stuff; how do I compile this in scratchbox?
I've been using the command gcc file.c -o program $(pkg-config --cflags --libs gtk+-2.0) -Wall to compile it. You can optionally add "x11 gdk-x11-2.0" before gtk+2.0 in the pkg-config line but it's not technically required as gtk+2.0 will automatically include them
 

The Following User Says Thank You to jstokes For This Useful Post:
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#23
Originally Posted by jstokes View Post
I've been using the command gcc file.c -o program $(pkg-config --cflags --libs gtk+-2.0) -Wall to compile it. You can optionally add "x11 gdk-x11-2.0" before gtk+2.0 in the pkg-config line but it's not technically required as gtk+2.0 will automatically include them
Thanks! Tried previously with this (found after googling): cc 'pkg-config --cflags --libs gtk+-2.0' theme.c theme but it failed with lots of errors. Your didn't give any errors, so I'm off to test now
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#24
Umm... stupid guestion again: what's the usage? Tried to understand the source and give the program arguments like "beta" "alpha" etc but it didn't actually do anything.
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#25
Originally Posted by d-iivil View Post
Umm... stupid guestion again: what's the usage? Tried to understand the source and give the program arguments like "beta" "alpha" etc but it didn't actually do anything.
There are no arguments.

It just tries to get the current theme details (last part of path and name) and give those details to the bits of Maemo that the personalisation_app does. Either it's doing everything and Maemo's refusing to do anything because it's the same theme (I know the program works to change themes because I first ran "personalisation" with a path to a different theme and running the program afterwards changed the screen itself) or because it's ending prematurely because running "personalisation" is failing. What does running "echo $?" directly after the program print? If it's 0, then the program's done what it can to try and get Maemo to refresh the theme. If it's 1, then try running the program as root with run-standalone.sh
 

The Following User Says Thank You to jstokes For This Useful Post:
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#26
Originally Posted by jstokes View Post
There are no arguments.

It just tries to get the current theme details (last part of path and name) and give those details to the bits of Maemo that the personalisation_app does. Either it's doing everything and Maemo's refusing to do anything because it's the same theme (I know the program works to change themes because I first ran "personalisation" with a path to a different theme and running the program afterwards changed the screen itself) or because it's ending prematurely because running "personalisation" is failing. What does running "echo $?" directly after the program print? If it's 0, then the program's done what it can to try and get Maemo to refresh the theme. If it's 1, then try running the program as root with run-standalone.sh
Oh yeah.. right after typing my message I realized it
Seems to work actually pretty well! It reloads changed icon theme etc @ app launcher. Will definitely use this with TC if it's ok with you?
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
Posts: 235 | Thanked: 339 times | Joined on Nov 2010
#27
Originally Posted by d-iivil View Post
Seems to work actually pretty well! It reloads changed icon theme etc @ app launcher. Will definitely use this with TC if it's ok with you?
Great!

Sure, no problems but I must stress that the ideas were stolen from a Nokia app
 

The Following User Says Thank You to jstokes For This Useful Post:
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#28
@d-iivil
Have you tried this:
Originally Posted by nicolai View Post
Have you tried matchbox-remote?
For example
/usr/bin/personalisation /usr/share/themes/beta
/usr/bin/matchbox-remote -t beta
switches to the theme "beta".
I thought it would have solved the icon reloading problem in qt-apps.
 
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#29
Originally Posted by jstokes View Post
Great!

Sure, no problems but I must stress that the ideas were stolen from a Nokia app
Just submitted updated version of TC to devel which now includes your code. Now user doesn't have to reboot the device after changing theme or icon theme. Super!
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
d-iivil's Avatar
Posts: 2,154 | Thanked: 2,186 times | Joined on Dec 2009 @ Hellsinki, Finland
#30
Originally Posted by nicolai View Post
@d-iivil
Have you tried this:


I thought it would have solved the icon reloading problem in qt-apps.
Hi, I tried and it changes the theme nicely, but won't update icons @ app launcher. There was also some other parts which weren't updated, but can't recall those anymore :/
__________________
If you're rich and you think I deserve a cold beer, you may donate one or two :-P

80's style stadium rock is back - FIRENOTE
Hi-Octane heavy metal - FORCE MAJEURE
 

The Following User Says Thank You to d-iivil For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 06:13.