-
-
Notifications
You must be signed in to change notification settings - Fork 49
Make Shutter read the xpm cursors x_hot and y_hot coordinates #813
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,40 @@ sub new { | |
| #~ print "$self dying at\n"; | ||
| #~ } | ||
|
|
||
| # Workaround for broken xpm parsing in glycin | ||
| sub parse_xpm_hotspot { | ||
| my ($xpm_path) = @_; | ||
| my ($x_hot, $y_hot); | ||
|
|
||
| open my $fh, '<', $xpm_path or do { | ||
| print "ERROR: Cannot open $xpm_path: $!\n"; | ||
| return (undef, undef); | ||
| }; | ||
|
|
||
| while (my $line = <$fh>) { | ||
| chomp($line); | ||
|
|
||
| # Look for the XPM header line with format: | ||
| # "width height ncolors chars_per_pixel [x_hot y_hot]" | ||
| # Example: "32 32 3 1 4 4" | ||
| if ($line =~ /"(\d+)\s+(\d+)\s+(\d+)\s+(\d+)(?:\s+(\d+)\s+(\d+))?/) { | ||
| my ($width, $height, $ncolors, $cpp, $xh, $yh) = ($1, $2, $3, $4, $5, $6); | ||
|
|
||
| if (defined($xh) && defined($yh)) { | ||
| $x_hot = $xh; | ||
| $y_hot = $yh; | ||
| } else { | ||
| print "DEBUG: No hotspot in header\n"; | ||
|
Photon89 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| last; # Header is on the first data line | ||
| } | ||
| } | ||
| close $fh; | ||
|
|
||
| return ($x_hot, $y_hot); | ||
| } | ||
|
|
||
| sub show { | ||
| my $self = shift; | ||
|
|
||
|
|
@@ -265,13 +299,29 @@ sub show { | |
| #http://www.inkscape.org | ||
| my @cursors = bsd_glob($self->{_dicons} . "/cursor/*"); | ||
| foreach my $cursor_path (@cursors) { | ||
| my ($cname, $folder, $type) = fileparse($cursor_path, qr/\.[^.]*/); | ||
| $self->{_cursors}{$cname} = Gtk3::Gdk::Pixbuf->new_from_file($cursor_path); | ||
| my ($cname, $folder, $type) = fileparse($cursor_path, qr/\.[^.]*/); | ||
| my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file($cursor_path); | ||
|
|
||
| if ($pixbuf) { | ||
| my $width = $pixbuf->get_width(); | ||
|
Photon89 marked this conversation as resolved.
|
||
| my $height = $pixbuf->get_height(); | ||
|
|
||
| # Parse hotspot from file | ||
| my ($x_hot, $y_hot) = parse_xpm_hotspot($cursor_path); | ||
|
|
||
| # Fallback to center if not found | ||
| $x_hot //= $width / 2; | ||
| $y_hot //= $height / 2; | ||
|
|
||
| #see 'man xcursor' for a detailed description | ||
| #of these values | ||
| $self->{_cursors}{$cname}{'x_hot'} = $self->{_cursors}{$cname}->get_option('x_hot'); | ||
| $self->{_cursors}{$cname}{'y_hot'} = $self->{_cursors}{$cname}->get_option('y_hot'); | ||
| # Store as a hash with pixbuf and hotspot data | ||
| $self->{_cursors}{$cname} = { | ||
| 'pixbuf' => $pixbuf, | ||
| 'x_hot' => $x_hot, | ||
| 'y_hot' => $y_hot, | ||
| }; | ||
| } else { | ||
|
Photon89 marked this conversation as resolved.
Outdated
|
||
| print "ERROR: Failed to load pixbuf\n"; | ||
|
Photon89 marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| #setu ui | ||
|
|
@@ -1147,17 +1197,21 @@ sub change_drawing_tool_cb { | |
| $self->{_btn_ok_c}->grab_focus; | ||
|
|
||
| } | ||
|
|
||
|
Photon89 marked this conversation as resolved.
Outdated
|
||
| if ($self->{_canvas} && $self->{_canvas}->get_window) { | ||
|
|
||
| if (exists $self->{_cursors}{$self->{_current_mode_descr}}) { | ||
| $cursor = Gtk3::Gdk::Cursor->new_from_pixbuf( | ||
| Gtk3::Gdk::Display::get_default(), $self->{_cursors}{$self->{_current_mode_descr}}, | ||
| $self->{_cursors}{$self->{_current_mode_descr}}{'x_hot'}, $self->{_cursors}{$self->{_current_mode_descr}}{'y_hot'}, | ||
| ); | ||
| } | ||
| if (exists $self->{_cursors}{$self->{_current_mode_descr}}) { | ||
|
Member
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. mix of tabs and spaces
Member
Author
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. Fixed! |
||
| my $cursor_data = $self->{_cursors}{$self->{_current_mode_descr}}; | ||
|
Member
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. still bad indent |
||
|
|
||
| $cursor = Gtk3::Gdk::Cursor->new_from_pixbuf( | ||
| Gtk3::Gdk::Display::get_default(), | ||
| $cursor_data->{'pixbuf'}, | ||
| $cursor_data->{'x_hot'}, | ||
| $cursor_data->{'y_hot'}, | ||
| ); | ||
| } | ||
|
|
||
| $self->{_canvas}->get_window->set_cursor($cursor); | ||
| $self->{_canvas}->get_window->set_cursor($cursor); | ||
| } | ||
|
|
||
| return TRUE; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.