Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Upgrade Gtk2 to Gtk3, and Gnome2::Wnck breaks

by Anonymous Monk
on Dec 29, 2018 at 10:33 UTC ( #1227808=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to upgrade some old code from Gtk2 to Gtk3.

Most dependencies still work, but Gnome2::Canvas and Gnome2::Wnck are a complete loss. I can replace Gnome2::Canvas with GooCanvas2 easily enough, but what can be done about replacing WNCK?

#!/usr/bin/perl package testgtk3; use strict; use diagnostics; use warnings; use Gtk3 '-init'; #use Gnome2::Canvas; use Gnome2::Wnck; my $window = Gtk3::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk3->main_quit; }); $window->set_border_width(5); $window->set_title('Gtk3 test'); my $button = Gtk3::Button->new("Hello world!"); $button->signal_connect(clicked => sub { my ($button) = @_; print "Hello world!"; $window->destroy(); }); $window->add($button); $button->show(); $window->show(); Gtk3->main(); 1;

Any such script with use Gnome2::Wnck produces a million error messages, starting with:

Subroutine Pango::Color::parse redefined at /usr/lib/x86_64-linux-gnu/perl/5.26/DynaLoader.pm line 204 (#1) (W redefine) You redefined a subroutine. To suppress this warning +, say { no warnings 'redefine'; eval "sub name { ... }"; } Subroutine Pango::Color::to_string redefined at /usr/lib/x86_64-linux-gnu/perl/5.26/DynaLoader.pm line 204 (#1) Subroutine Pango::Attribute::end_index redefined at /usr/lib/x86_64-linux-gnu/perl/5.26/DynaLoader.pm line 204 (#1) Subroutine Pango::Attribute::start_index redefined at /usr/lib/x86_64-linux-gnu/perl/5.26/DynaLoader.pm line 204 (#1)

Replies are listed 'Best First'.
Re: Upgrade Gtk2 to Gtk3, and Gnome2::Wnck breaks
by zentara (Archbishop) on Dec 29, 2018 at 22:21 UTC
    Hi, what exactly are you trying to do with Gnome2::Wnck ? Pager? Get root window?

    I'm not really a human, but I play one on earth. ..... an animated JAPH

      >Hi, what exactly are you trying to do with Gnome2::Wnck ?

      Window tiling on multiple workspaces. Firstly, I use WNCK get a list of workspaces and their sizes. Then I create a test Gtk2::Window, size 100x100. Then I use WNCK to get the actual size of the window. This gives me the size of window controls.

      Then I draw a test window in the top left/bottom right corners of the window. Then I use WNCK to get the actual size/position of the window. This gives me the size and position of taskbars/panels, which gives me the size of the available workspace.

      Specifically, these are the operations I use. I have never found any alternative to WNCK, and of course finding something that works on MS Windows as well as Linux is just a foolish pipe dream :)

      Get the default screen and workspace

      $screen = Gnome2::Wnck::Screen->get_default() $screen->force_update(); $workspace = $screen->get_active_workspace();

      Get remaining workspaces

      do { $otherWorkspace = $workspace->get_neighbor('WNCK_MOTION_RIGHT'); until (! $otherWorkspace);

      Get the size of a workspace

      $workspace->get_width(); $workspace->get_height();

      Move a window to a workspace

      $wnckWin->move_to_workspace($workspace);

      Get a window's current screen

      $screen = $wnckWin->get_screen();

      Get the system name/number for a workspace

      $num = $workspace->get_number(); $name = $workspace->get_name();

      Get/set the size and position of the window

      $wnckWin->get_client_window_geometry(); $wnckWin->set_geometry( 'WNCK_WINDOW_GRAVITY_CURRENT', [ 'WNCK_WINDOW_CHANGE_X', 'WNCK_WINDOW_CHANGE_Y', 'WNCK_WINDOW_CHANGE_WIDTH', 'WNCK_WINDOW_CHANGE_HEIGHT', ], $x, $y, $width, $height, );

      Minimise/unminimise windows

      $wnckWin->unminimize(time()); $wnckWin->minimize(); if (wnckWin->is_minimized) { ... }

      Given a WNCK window, find the equivalent Gtk2 window

      foreach my $gtkWin (Gtk2::Window->list_toplevels()) { $wnckWinXid = $wnckWin->get_xid(); $gtkWinXid = $gtkWin->get_xid(); if ($wnckWinXid eq $gtkWinXid) { ... } }

      Given a Gtk window, find the equivalent WNCK window

      $gdkWin = $gtkWin->get_window(); $winXid = $gdkWin->get_xid(); $wnckScreen->force_update(); foreach my $wnckWin ($wnckScreen->get_windows()) { my $wnckWinXid = $wnckWin->get_xid(); if ($wnckWinXid && $wnckWinXid eq $winXid) { ... }

      Find the WNCK window for "Notepad" or "Firefox", or whatever

      $wnckScreen->force_update(); foreach my $wnckWin ($wnckScreen->get_windows()) { if ($wnckWin->get_name() eq 'Notepad') { ... } }
        Hi, X11::WMCtrl will do many of your tasks, or use the wmctrl directly. You may also want to dig into Gtk3's capabilities. Search google for "gtk3 get active window" and you will find the code.

        I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Upgrade Gtk2 to Gtk3, and Gnome2::Wnck breaks
by Anonymous Monk on Dec 30, 2018 at 03:15 UTC
    Old code works? Keep it :)
      I agree, the Gtk2 libraries will be around and installed as default by all the distros for a very long time.

      I'm not really a human, but I play one on earth. ..... an animated JAPH

        Gtk2 is probably immortal, but Gnome2 components definitely aren't. Gnome2::VFS is already being removed from Linux distros, and presumably it's only a matter of type before Gnome2::Wnck and Gnome2::Canvas share the same fate. Hence the need to upgrade.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1227808]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2019-11-18 21:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (92 votes). Check out past polls.

    Notices?