Leser: 1
|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use Tk;
my $mw = tkinit;
$mw->bind('<Configure>' => sub { $mw->dock_window(50) });
MainLoop();
package MainWindow;
sub dock_window {
my $self = shift;
my $px = shift || 10; # Pixel vom Bildschirmrand
my $sh = $self->screenheight();
my $sw = $self->screenwidth();
my($width, $height, $pos_x, $pos_y) = split(/[x+-]/, $self->geometry());
my $pos_x2 = $pos_x + $width;
my $pos_y2 = $pos_y + $height;
return if ($pos_x == 0 || $pos_x > $px)
&& ($pos_x2 == $sw || $pos_x2 < ($sw - $px))
&& ($pos_y == 0 || $pos_y > $px)
&& ($pos_y2 == $sh || $pos_y2 < ($sh - $px));
$pos_x = $pos_x <= $px ? 0 : $pos_x;
$pos_y = $pos_y <= $px ? 0 : $pos_y;
$pos_x = $pos_x2 > ($sw - $px) ? $sw - $width : $pos_x;
$pos_y = $pos_y2 > ($sh - $px) ? $sh - $height : $pos_y;
$self->geometry(sprintf("+%s+%s", $pos_x, $pos_y));
}
my($width, $height, $pos_x, $pos_y) = split(/[x+-]/, $self->geometry());
1
2
3
4
5
6
7
8
9
10
11
12
13
sub parse_geometry_string {
my $geometry = shift;
my @extends = (0, 0, 0, 0);
if ($geometry =~ /([-+]?\d+)x([-+]?\d+)/) {
$extends[GEOMETRY_WIDTH] = $1;
$extends[GEOMETRY_HEIGHT] = $2;
}
if ($geometry =~ /[-+]([-+]?\d+)[-+]([-+]?\d+)/) {
$extends[GEOMETRY_X] = $1;
$extends[GEOMETRY_Y] = $2;
}
@extends;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
use strict;
use warnings;
use constant GEOMETRY_WIDTH => 0;
use constant GEOMETRY_HEIGHT => 1;
use constant GEOMETRY_X => 2;
use constant GEOMETRY_Y => 3;
my $geom = "800x600-750-1010";
print "'$geom' liefert '", join(", ", parse_geometry_string($geom)), "'.\n";
sub parse_geometry_string {
my $geometry = shift;
my @extends = (0, 0, 0, 0);
if ($geometry =~ /([-+]?\d+)x([-+]?\d+)/) {
$extends[GEOMETRY_WIDTH] = $1;
$extends[GEOMETRY_HEIGHT] = $2;
}
if ($geometry =~ /[-+]([-+]?\d+)[-+]([-+]?\d+)/) {
$extends[GEOMETRY_X] = $1;
$extends[GEOMETRY_Y] = $2;
}
@extends;
}
'800x600-750-1010' liefert '800, 600, 750, 1010'.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use strict;
use warnings;
use constant GEOMETRY_WIDTH => 0;
use constant GEOMETRY_HEIGHT => 1;
use constant GEOMETRY_X => 2;
use constant GEOMETRY_Y => 3;
my $geom = "800x600-750-1010";
print "'$geom' liefert '", join(", ", parse_geometry_string2($geom)), "'.\n";
sub parse_geometry_string {
my $geometry = shift;
my @extends = (0, 0, 0, 0);
if ($geometry =~ /([-+]?\d+)x([-+]?\d+)/) {
$extends[GEOMETRY_WIDTH] = $1;
$extends[GEOMETRY_HEIGHT] = $2;
}
if ($geometry =~ /[-+]([-+]?\d+)[-+]([-+]?\d+)/) {
$extends[GEOMETRY_X] = $1;
$extends[GEOMETRY_Y] = $2;
}
@extends;
}
sub parse_geometry_string2 {
my $geometry = shift;
my @extends = (0, 0, 0, 0);
if ($geometry =~ /([-+]?\d+)x([-+]?\d+)/) {
$extends[GEOMETRY_WIDTH] = $1;
$extends[GEOMETRY_HEIGHT] = $2;
}
if ($geometry =~ /([-+]\d+)([-+]\d+)/) {
$extends[GEOMETRY_X] = $1;
$extends[GEOMETRY_Y] = $2;
}
@extends;
}
'800x600-750-1010' liefert '800, 600, -750, -1010'.
|< 1 2 >| | 12 Einträge, 2 Seiten |