| 1 | # Copyright 2010, 2011, 2012, 2014, 2017 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Glib-Ex-ConnectProperties. | ||
| 4 | # | ||
| 5 | # Glib-Ex-ConnectProperties is free software; you can redistribute it and/or | ||
| 6 | # modify it under the terms of the GNU General Public License as published | ||
| 7 | # by the Free Software Foundation; either version 3, or (at your option) any | ||
| 8 | # later version. | ||
| 9 | # | ||
| 10 | # Glib-Ex-ConnectProperties is distributed in the hope that it will be | ||
| 11 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
| 13 | # Public License for more details. | ||
| 14 | # | ||
| 15 | # You should have received a copy of the GNU General Public License along | ||
| 16 | # with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | package Glib::Ex::ConnectProperties::Element::screen_size; | ||
| 19 | use 5.008; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Carp; | ||
| 23 | use Glib; | ||
| 24 | use Scalar::Util; | ||
| 25 | use base 'Glib::Ex::ConnectProperties::Element'; | ||
| 26 | |||
| 27 | our $VERSION = 20; | ||
| 28 | |||
| 29 | |||
| 30 | # _gdk_x11_screen_size_changed() emits size-changed if pixels changed, but | ||
| 31 | # not if pixels same but millimetres changed. | ||
| 32 | # | ||
| 33 | # _gdk_x11_screen_process_monitors_change() emits monitors-changed for any | ||
| 34 | # RandrNotify. | ||
| 35 | # | ||
| 36 | |||
| 37 | use constant pspec_hash => | ||
| 38 | do { | ||
| 39 | # dummy name since paramspec name cannot be empty string | ||
| 40 | my $pspec = Glib::ParamSpec->int ('width', # name, unused | ||
| 41 | '', # nick, unused | ||
| 42 | '', # blurb, unused | ||
| 43 | 0, 32767, # min,max, unused | ||
| 44 | 0, # default, unused | ||
| 45 | 'readable'); | ||
| 46 | ({ | ||
| 47 | 'width' => $pspec, | ||
| 48 | 'height' => $pspec, | ||
| 49 | 'width-mm' => $pspec, | ||
| 50 | 'height-mm' => $pspec, | ||
| 51 | }) | ||
| 52 | }; | ||
| 53 | |||
| 54 | sub read_signal { | ||
| 55 | my ($self) = @_; | ||
| 56 | if ($self->{'pname'} =~ /mm/) { | ||
| 57 | # "width-mm", "height-mm" | ||
| 58 | my $screen = $self->{'object'}; | ||
| 59 | if ($screen->signal_query('monitors-changed')) { | ||
| 60 | # new in gtk 2.14 | ||
| 61 | return 'monitors-changed'; | ||
| 62 | } else { | ||
| 63 | # before gtk 2.14 there was no randr listening and width_mm/height_mm | ||
| 64 | # were unchanging | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | } else { | ||
| 68 | # "width", "height" | ||
| 69 | return 'size-changed'; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | my %method = ('width' => 'get_width', | ||
| 74 | 'height' => 'get_height', | ||
| 75 | 'width-mm' => 'get_width_mm', | ||
| 76 | 'height-mm' => 'get_height_mm', | ||
| 77 | ); | ||
| 78 | sub get_value { | ||
| 79 | my ($self) = @_; | ||
| 80 | my $method = $method{$self->{'pname'}}; | ||
| 81 | return $self->{'object'}->$method; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||
| 85 | __END__ |