shutter / lib /Shutter /App /Environment.pm
runitx's picture
Claude Opus 5.5
Move modules from share/shutter/resources/modules to lib/
a19d10a unverified
Raw History Blame Contribute Delete
4.84 kB
###################################################
#
# Copyright (C) 2008-2013 Mario Kemper <mario.kemper@gmail.com>
#
# This file is part of Shutter.
#
# Shutter is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Shutter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Shutter; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
package Shutter::App::Environment;
#modules
#--------------------------------------
use 5.010;
use utf8;
use strict;
use warnings;
use Gtk3;
use Net::DBus;
use File::Glob qw/ bsd_glob /;
use File::Which;
#Glib
use Glib qw/TRUE FALSE/;
require Shutter::App::Directories;
use Exporter qw(import);
our @EXPORT_OK = qw(control_wm_settings init_unsaved_files init_debug_output);
#--------------------------------------
# Disable (mode 'start') or restore (mode 'stop') compiz focus prevention via DBus.
# Returns the previous focus_prevention_level, or -1 if compiz is not reachable.
sub control_wm_settings {
my $mode = shift;
my $restore_value = shift;
#compiz via dbus
my $bus = undef;
my $compiz = undef;
my $fpl = undef;
#disable focus_prevention
my $curr_value = -1;
#disable focus prevention when using compiz
eval {
$bus = Net::DBus->find;
#Get a handle to the compiz service
$compiz = $bus->get_service("org.freedesktop.compiz");
#Get the relevant object
$fpl = $compiz->get_object("/org/freedesktop/compiz/core/screen0/focus_prevention_level", "org.freedesktop.compiz");
};
if ($@) {
warn "INFO: DBus connection to org.freedesktop.compiz failed --> skipping compiz related tasks\n\n";
warn $@ . "\n\n";
return $curr_value;
}
if (defined $fpl && $fpl) {
eval {
if ($mode eq 'start') {
#save and return current value
if (defined $fpl && $fpl) {
$curr_value = $fpl->get;
}
if (defined $fpl && $fpl && $fpl->get != 0) {
$fpl->set(0);
}
#re-enable focus prevention -> restore value
} elsif ($mode eq 'stop') {
if (defined $fpl && $fpl && defined $restore_value) {
$fpl->set($restore_value);
} elsif (defined $fpl && $fpl) {
$fpl->set(1);
}
}
};
if ($@) {
warn "ERROR: Unable to set/get focus_level_prevention --> skipping compiz related tasks\n\n";
warn $@ . "\n\n";
}
}
return $curr_value;
}
# Delete files in the 'unsaved' cache dir that are not part of the current session.
# $sc: Shutter::App::Common; $get_key_by_filename: coderef returning the session key for a file.
sub init_unsaved_files {
my ($sc, $get_key_by_filename) = @_;
#delete all files in this folder
#except the ones that are in the current session
my @unsaved_files = bsd_glob(Shutter::App::Directories::get_cache_dir() . "/*");
foreach my $unsaved_file (@unsaved_files) {
utf8::decode $unsaved_file;
print $unsaved_file, " checking \n" if $sc->get_debug;
unless ($get_key_by_filename->($unsaved_file)) {
print $unsaved_file, " deleted \n" if $sc->get_debug;
unlink $unsaved_file;
}
}
return;
}
# Print system/library version information (used with --debug).
# $version, $rev: SHUTTER_VERSION and SHUTTER_REV from bin/shutter.
sub init_debug_output {
my ($version, $rev) = @_;
print "\nINFO: gathering system information...";
print "\n";
print "\n";
print "Shutter ";
print $version;
print ' ';
print $rev;
print "\n";
#kernel info
if (File::Which::which('uname')) {
print `uname -a`, "\n";
}
eval {
open my $fh, '<', '/etc/os-release' or die; ## no critic (InputOutput::RequireBriefOpen)
my %map = map {
chomp;
my ($key, $value) = split /=/, $_, 2;
$value =~ s/^(['"])(.*)\1$/$2/;
($key, $value)
} <$fh>;
local $, = ' ';
say grep { $_ } map { $map{$_} } qw/NAME VERSION_ID BUILD_ID/;
};
say "Cannot open /etc/os-release" if $@;
printf "Glib %s \n", $Glib::VERSION;
printf "Gtk3 %s \n", $Gtk3::VERSION;
print "\n";
# The version info stuff appeared in 1.040.
print "Glib built for " . join(".", Glib->GET_VERSION_INFO) . ", running with " . join(".", Glib::major_version(), Glib::minor_version(), Glib::micro_version()) . "\n"
if $Glib::VERSION >= 1.040;
print "Gtk3 built for " . join(".", Gtk3->GET_VERSION_INFO) . ", running with " . join(".", Gtk3::major_version(), Gtk3::minor_version(), Gtk3::micro_version()) . "\n"
if $Gtk3::VERSION >= 1.040;
print "\n";
return TRUE;
}
1;