Fedora Linux Support Community & Resources Center
  #1  
Old 1st March 2017, 04:55 PM
tux4me Offline
Registered User
 
Join Date: Nov 2008
Location: Denmark
Age: 50
Posts: 126
linuxfedorafirefox
How to reset Gnome-shell-theme in C++

Im tired of missing Gnome settings, so im doing a GUI app in GTKMM to make Gnome-shell-themes and try them out instant.

All i have is the gnome-shell.css file (resource) as i cant find any documentation or references to css names / classes / entities ... whatever its all called in css, so i just use what is in the gnome-shell.css file, for now.

Gnome just gets so much nicer if its easy to change fonts , sizes, colors, GUI etc. in every single item covered by gnome-shell-theme.

Serious simple so i dont understand why there is no such GUI already ?

Anyway, my question is : How do i reset gnome-shell-theme from inside my C++ application ?

I know the "ALT -> F2 -> rt" and command line "gnome-shell --replace" (which reset all gnome-shell)
so i guess its in some header file [...]

It would just make this application perfect
__________________
Now a pure mini-ITX Gaming rig, for Fedora !
Asus z170i PRO Gaming Motherboard, with onboard WIFI.
Intel i7 6700K - 16 GB RAM - M.2 (nvme) Intel SSD 6 PRO - Samsung EVO SSD via SATA
nVidia EVGA SC 6gb GTX 1060 - Acer Predator 144 hz Gaming Monitor with G-Sync.

Last edited by tux4me; 1st March 2017 at 05:01 PM.
Reply With Quote
  #2  
Old 1st March 2017, 11:22 PM
ocratato Offline
Registered User
 
Join Date: Oct 2010
Location: Canberra
Posts: 2,484
linuxfirefox
Re: How to reset Gnome-shell-theme in C++

A few random ideas.

You can get the gnome shell to restart by sending it a sighup signal.

The gnome shell has a dbus interface method called Eval which will get the shell to run a javascript.
__________________
Has anyone seriously considered that it might be turtles all the way down?
That's very old fashioned thinking.
The current model is that it's holographic nested virtualities of turtles, all the way down.
Reply With Quote
  #3  
Old 2nd March 2017, 12:28 AM
tux4me Offline
Registered User
 
Join Date: Nov 2008
Location: Denmark
Age: 50
Posts: 126
linuxfedorafirefox
Re: How to reset Gnome-shell-theme in C++

nice thanks.

You made me look for DBus and found this solution :
Quote:
dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
Looks like i will have to read up on using glibmm DBus API, tomorrow.
__________________
Now a pure mini-ITX Gaming rig, for Fedora !
Asus z170i PRO Gaming Motherboard, with onboard WIFI.
Intel i7 6700K - 16 GB RAM - M.2 (nvme) Intel SSD 6 PRO - Samsung EVO SSD via SATA
nVidia EVGA SC 6gb GTX 1060 - Acer Predator 144 hz Gaming Monitor with G-Sync.
Reply With Quote
  #4  
Old 2nd March 2017, 03:36 PM
tux4me Offline
Registered User
 
Join Date: Nov 2008
Location: Denmark
Age: 50
Posts: 126
linuxfedorafirefox
Re: How to reset Gnome-shell-theme in C++

I decided to look in /proc to see if i could get PID of gnome-shell, and maybe use a signal to reset gnome-shell.

It looked easy, but then i saw that there is 2 x gnome-shell running

One for GDM, and one for user, aka me.

I use boost filesystem since its on its way into c++17, and its new to me, so its practice

Code:
// #include <boost/filesystem.hpp>
// LDFLAGS -lboost_system  -lboost_filesystem
bool found = false;
path p ("/proc");

try
  {
  if (exists(p)) // if "/proc" dir exists
    {
    if (is_directory(p)) // if its a dir [...]
      {
      for (auto&& x : directory_iterator(p)) // iterate through entries in /proc 
        {
        if (is_directory(x)) // if its a dir ... dirname is pid
          {
          for (auto&& y : directory_iterator(x)) // iterate through entries
            {
            if(y.path().filename().string() == "cmdline") // look for file "cmdline"
              {
              std::ifstream cmdline(y.path().string()); // open file cmdline
              
              if(cmdline) // if file is open
                {
                std::string cmdline_content((std::istreambuf_iterator<char>(cmdline) ),
                                            (std::istreambuf_iterator<char>()    ) );                    

                std::size_t pos = cmdline_content.find_last_of("/");
                if (pos != std::string::npos && 
                    cmdline_content.substr(pos+1, 11) == "gnome-shell") 
                if (cmdline_content.substr(pos+1).length() == 12  ) // somehow its 12 
                  {
                  // gnome-shell found
                  //
                  // get user loginuid
                  std::ifstream self_loginuid("/proc/self/loginuid");
                  std::string self_content((std::istreambuf_iterator<char>(self_loginuid)),
                                           (std::istreambuf_iterator<char>()    ) );
                  // get gnome-shell loginuid                
                  std::ifstream gshell_loginuid(x.path().string() + "/loginuid");
                  
                  std::string gshell_content((std::istreambuf_iterator<char>(gshell_loginuid)),
                                             (std::istreambuf_iterator<char>()    ) );
                  // compare loginuid's                  
                  if ( gshell_content == self_content )
                    {
                    std::string pid = x.path().filename().string();
                    std::cout << "gnome-shell pid is: " << pid << std::endl;
                    found=true;
                    //kill(atoi(pid.c_str()), SIGHUP); // uncomment to reset gnome-shell
                    }
                  }//if
                }//if
              }//if
            if(found) break;
            }//for
          }//if
        if(found) break;
        }//for
      }//if
    else
      std::cout << p << " exists, but is not a regular file or directory\n";
    }//if
  else
    std::cout << p << " does not exist\n";
  }//try
catch (const filesystem_error& ex)
  {
  std::cout << ex.what() << '\n';
  }
EDIT:
Well it turns out there is a "/proc/self/loginuid" i can use to compare, and it looks like a stable solution to me.

I have update my code snippet to reflect the solution i now consider for solved.
__________________
Now a pure mini-ITX Gaming rig, for Fedora !
Asus z170i PRO Gaming Motherboard, with onboard WIFI.
Intel i7 6700K - 16 GB RAM - M.2 (nvme) Intel SSD 6 PRO - Samsung EVO SSD via SATA
nVidia EVGA SC 6gb GTX 1060 - Acer Predator 144 hz Gaming Monitor with G-Sync.

Last edited by tux4me; 2nd March 2017 at 04:54 PM.
Reply With Quote
  #5  
Old 4th March 2017, 08:01 PM
tux4me Offline
Registered User
 
Join Date: Nov 2008
Location: Denmark
Age: 50
Posts: 126
linuxfedorafirefox
Re: How to reset Gnome-shell-theme in C++

After some casual reading on the DBus, i actually got a nice working solution.
(like hours of "#"#"# google surf)

As always ... so easy ?

It feels like the best way to do it


Code:
void dbus_proxy(Glib::RefPtr<Gio::AsyncResult>& result)
  {
  const auto proxy = Gio::DBus::Proxy::create_finish(result);

  if (!proxy)
    {
    std::cerr << "failed to create proxy" << std::endl;
    return;
    }

  try
    {
    //const Glib::ustring str = "global.reexec_self()";  // to reset gnome-shell
    const Glib::ustring str = "Main.loadTheme();"; // to reload a (changed) theme
    const auto str_var = Glib::Variant<Glib::ustring>::create(str);
    Glib::VariantContainerBase var = Glib::VariantContainerBase::create_tuple(str_var);
   
    proxy->call_sync("Eval", var);

    }
  catch (const Glib::Error& error)
    {
    std::cerr << "Got an error: '" << error.what() << "'." << std::endl;
    }
  }

int main()
  {
  // Create the Connection to the bus.
  auto conn = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION);

  // Create the proxy to the bus asynchronously.
  Gio::DBus::Proxy::create(conn, "org.gnome.Shell","/org/gnome/Shell","org.gnome.Shell", 
          sigc::ptr_fun(&dbus_proxy));
  }
__________________
Now a pure mini-ITX Gaming rig, for Fedora !
Asus z170i PRO Gaming Motherboard, with onboard WIFI.
Intel i7 6700K - 16 GB RAM - M.2 (nvme) Intel SSD 6 PRO - Samsung EVO SSD via SATA
nVidia EVGA SC 6gb GTX 1060 - Acer Predator 144 hz Gaming Monitor with G-Sync.

Last edited by tux4me; 5th March 2017 at 09:21 AM.
Reply With Quote
  #6  
Old 4th March 2017, 11:28 PM
ocratato Offline
Registered User
 
Join Date: Oct 2010
Location: Canberra
Posts: 2,484
linuxfirefox
Re: How to reset Gnome-shell-theme in C++

Good work.

Perhaps you could add some of the dbus references you found useful.
__________________
Has anyone seriously considered that it might be turtles all the way down?
That's very old fashioned thinking.
The current model is that it's holographic nested virtualities of turtles, all the way down.
Reply With Quote
  #7  
Old 5th March 2017, 07:00 AM
tux4me Offline
Registered User
 
Join Date: Nov 2008
Location: Denmark
Age: 50
Posts: 126
linuxfedorafirefox
Re: How to reset Gnome-shell-theme in C++

Its all put together with small bits and hints, and there is much new stuff to me, in that small amount of code.
I found a code example of getting result back from another DBus interface, which helped me with the structure of the call.

Then i found a C example of a simple Variant made of a string, and with some trial and error i figured out the solution.
There is still a bit to read about if i want to understand it fully.

To me it looks like there is many ways to make a connection to DBus with Glib / Gio.
So i did most of my reading in Glibmm / Giomm documentation.
From there i could see what stuff was needed to make the connection.

There is events like "getting the bus", "getting the name", "loosing the name" which i was working on,
but ended up with the solution i showed here.

I found this command line helpful, which list all methods/properties/signals of gnome-shell interface. (any interface)
Code:
qdbus org.gnome.Shell /org/gnome/Shell
Only useful method listed was "Eval", so now i had to find out how to use "Eval" in a DBus call ....
As you had mention, too.

I only needed to reset gnome-shell and forget about DBus, but i got a link to a "Using the DBUS C API"
that gives a good idea of what its about.

Edit : But i did never figure out how to reset only the theme as in "ALT + F2 -> rt " ... still in my brain

EDIT EDIT: haha i got it !! "Main.loadTheme();" rather than "global.reexec_self();" to only reload a changed theme, man is this SO solved now !!

I change the previous code to "Main.loadTheme();" and leave "global.reexec_self();" as a comment

It actually matter a lot, to ONLY reset theme, as resetting gnome-shell also reset my nvidia driver to defaults, loosing my 144 hz setup, as i set when i log in. (and what else .....)
With only resetting the theme, nothing else changes (as far as i can see)
__________________
Now a pure mini-ITX Gaming rig, for Fedora !
Asus z170i PRO Gaming Motherboard, with onboard WIFI.
Intel i7 6700K - 16 GB RAM - M.2 (nvme) Intel SSD 6 PRO - Samsung EVO SSD via SATA
nVidia EVGA SC 6gb GTX 1060 - Acer Predator 144 hz Gaming Monitor with G-Sync.

Last edited by tux4me; 5th March 2017 at 09:24 AM.
Reply With Quote
Reply

Tags
gnomeshelltheme, reset

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
command to reset gnome shell? thkang Using Fedora 1 29th September 2012 01:19 PM
Can't enable Shell Theme in Gnome Tweak Tool... thebelial Using Fedora 17 31st December 2011 12:17 PM
How to change Gnome-Shell theme? Icedrake Using Fedora 6 22nd November 2011 12:40 AM
A theme switch left me without gnome-shell Boricua F16 Development 3 1st October 2011 02:56 PM
GTK2 Theme Broken in Gnome Shell dmaxel Using Fedora 1 7th June 2011 03:01 AM


Current GMT-time: 20:20 (Thursday, 30-03-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat