-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplementation for Maurizio's gnome-screenshot hack #667
Draft
Photon89
wants to merge
7
commits into
master
Choose a base branch
from
reenableselect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
923d141
Re-enable select button for Photon's gnome testing
DarthGandalf e9c5f90
Add Gnome Wayland Selector to main Shutter file
Photon89 2732b31
Add GnomeWayland selector module
Photon89 cacd363
Properly handle temporary file and add timeout
Photon89 fd9f56a
Since we are resorting to hacks, added the slurp module for non-Gnome…
Photon89 ba610e2
Added slurp selector module - untested so far!
Photon89 a38454c
Fixed copy & paste mistake
Photon89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
share/shutter/resources/modules/Shutter/Screenshot/SelectorGnomeWayland.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
################################################### | ||
# | ||
# Copyright (C) 2008-2013 Mario Kemper <[email protected]> | ||
# | ||
# 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 | ||
# | ||
################################################### | ||
|
||
#perl -x -S perltidy -l=0 -b "%f" | ||
|
||
package Shutter::Screenshot::SelectorGnomeWayland; | ||
|
||
#modules | ||
#-------------------------------------- | ||
use utf8; | ||
use strict; | ||
use warnings; | ||
|
||
use Shutter::Screenshot::Main; | ||
use Shutter::Screenshot::History; | ||
use File::Temp qw/ tempfile tempdir /; | ||
|
||
use Data::Dumper; | ||
our @ISA = qw(Shutter::Screenshot::Main); | ||
|
||
#Glib | ||
use Glib qw/TRUE FALSE/; | ||
|
||
#-------------------------------------- | ||
|
||
sub new { | ||
my $class = shift; | ||
|
||
#call constructor of super class (shutter_common, include_cursor, delay, notify_timeout) | ||
my $self = $class->SUPER::new(shift, shift, shift, shift); | ||
|
||
$self->{_hide_time} = shift; #a short timeout to give the server a chance to redraw the area that was obscured | ||
|
||
$self->{_dpi_scale} = Gtk3::Window->new('toplevel')->get('scale-factor'); | ||
|
||
bless $self, $class; | ||
return $self; | ||
} | ||
|
||
sub select_gnome_wayland { | ||
my $self = shift; | ||
|
||
#return value | ||
my $output = 5; | ||
|
||
my $cmdcursor = undef; | ||
|
||
if ($self->{_include_cursor}) { | ||
$cmdcursor = "-p"; | ||
} | ||
else { | ||
$cmdcursor = ""; | ||
} | ||
|
||
#A short timeout to give the server a chance to | ||
#redraw the area | ||
Glib::Timeout->add( | ||
$self->{_hide_time}, | ||
sub { | ||
Gtk3->main_quit; | ||
return FALSE; | ||
}); | ||
Gtk3->main(); | ||
|
||
my $fh = File::Temp->new(); | ||
my $tmpfilename = $fh->filename; | ||
|
||
system("gnome-screenshot", "-a", "-f", $tmpfilename, "-d", $self->{_delay}, $cmdcursor); | ||
|
||
my $image = Gtk3::Image->new(); | ||
$image->set_from_file($tmpfilename); | ||
$output = $image->get_pixbuf(); | ||
|
||
my $d = $self->{_sc}->get_gettext; | ||
|
||
return $output; | ||
} | ||
|
||
|
||
sub redo_capture { | ||
my $self = shift; | ||
my $output = 3; | ||
if (defined $self->{_history}) { | ||
($output) = $self->get_pixbuf_from_drawable($self->{_history}->get_last_capture); | ||
} | ||
return $output; | ||
} | ||
|
||
sub get_history { | ||
my $self = shift; | ||
return $self->{_history}; | ||
} | ||
|
||
sub get_error_text { | ||
my $self = shift; | ||
return $self->{_error_text}; | ||
} | ||
|
||
sub get_action_name { | ||
my $self = shift; | ||
return $self->{_action_name}; | ||
} | ||
|
||
sub quit { | ||
my $self = shift; | ||
|
||
$self->ungrab_pointer_and_keyboard(FALSE, FALSE, TRUE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did it grab them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another unnecessary remainder. |
||
$self->clean; | ||
} | ||
|
||
sub clean { | ||
my $self = shift; | ||
|
||
$self->{_selector}->signal_handler_disconnect($self->{_selector_handler}); | ||
$self->{_view}->signal_handler_disconnect($self->{_view_zoom_handler}); | ||
$self->{_view}->signal_handler_disconnect($self->{_view_button_handler}); | ||
$self->{_view}->signal_handler_disconnect($self->{_view_event_handler}); | ||
$self->{_select_window}->signal_handler_disconnect($self->{_key_handler}); | ||
$self->{_select_window}->destroy; | ||
$self->{_zoom_window}->destroy; | ||
$self->{_prop_window}->destroy; | ||
} | ||
|
||
1; |
95 changes: 95 additions & 0 deletions
95
share/shutter/resources/modules/Shutter/Screenshot/SelectorSlurpWayland.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use utf8; | ||
use strict; | ||
use warnings; | ||
use Net::DBus; | ||
use Net::DBus::Reactor; | ||
use Class::Struct; | ||
use Data::Dumper; | ||
|
||
package Shutter::Screenshot::SelectorSlurpWayland; | ||
|
||
sub xdg_portal { | ||
my $screenshooter = shift; | ||
my $reactor = Net::DBus::Reactor->main; | ||
my $bus = Net::DBus->find; | ||
my $me = $bus->get_unique_name; | ||
$me =~ s/\./_/g; | ||
$me =~ s/^://g; | ||
|
||
my $pixbuf; | ||
my $output; | ||
|
||
eval { | ||
my $portal_service = $bus->get_service('org.freedesktop.portal.Desktop'); | ||
my $portal = $portal_service->get_object('/org/freedesktop/portal/desktop', 'org.freedesktop.portal.Screenshot'); | ||
|
||
my $num; | ||
my $cb = sub { | ||
($num, $output) = @_; | ||
$reactor->shutdown; | ||
}; | ||
|
||
my $token = 'shutter' . rand; | ||
$token =~ s/\.//g; | ||
my $request = $portal_service->get_object("/org/freedesktop/portal/desktop/request/$me/$token", 'org.freedesktop.portal.Request'); | ||
my $conn = $request->connect_to_signal(Response => $cb); | ||
my $request_path = $portal->Screenshot('', {handle_token=>$token}); | ||
if ($request->get_object_path ne $request_path) { | ||
$request->disconnect_from_signal(Response => $conn); | ||
$request = $portal_service->get_object($request_path, 'org.freedesktop.portal.Request'); | ||
$conn = $request->connect_to_signal(Response => $cb); | ||
} | ||
$reactor->run; | ||
$request->disconnect_from_signal(Response => $conn); | ||
if ($num != 0) { | ||
$screenshooter->{_error_text} = "Response $num from XDG portal"; | ||
return 9; | ||
} | ||
my $giofile = Glib::IO::File::new_for_uri($output->{uri}); | ||
print "xdg portal: got file ".$giofile->get_path."\n"; | ||
$pixbuf = Gtk3::Gdk::Pixbuf->new_from_file($giofile->get_path); | ||
my $slurpoutput = `slurp`; | ||
my ($x, $y, $width, $height) = split /[,x ]/, $slurpoutput; | ||
my $s = { | ||
'y' => $y, | ||
'width' => $width, | ||
'height' => $height, | ||
'x' => $x | ||
}; | ||
|
||
$output = take_screenshot($s, $pixbuf); | ||
$giofile->delete; | ||
}; | ||
if ($@) { | ||
$screenshooter->{_error_text} = $@; | ||
return 9; | ||
}; | ||
|
||
return $output; | ||
} | ||
|
||
sub take_screenshot { | ||
#my $self = shift; | ||
my $s = shift; | ||
my $clean_pixbuf = shift; | ||
|
||
#my $d = $self->{_sc}->get_gettext; | ||
|
||
my $output; | ||
|
||
#no delay? then we take a subsection of the pixbuf in memory | ||
if ($s && $clean_pixbuf ) { | ||
|
||
$output = $clean_pixbuf->new_subpixbuf($s->{x}, $s->{y}, $s->{width}, $s->{height}); | ||
|
||
print "DEBUG OUTPUT=" . $output . "\n"; | ||
|
||
#if there is a delay != 0 set, we have to wait and get a new pixbuf from the root window | ||
} else { | ||
$output = 0; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
1; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't actually redo any capture, will it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is just a remainder from the SelectorAdvance.pm module which I took as a base. I have some ideas, how redo could be possible (make a full screen screenshot with gnome-screenshot, then choose the proper area, but this would require to somehow get the information, what the proper area is, as now gnome-screenshot is responsible for doing the selection) but nothing working yet.