File: GtkImport.pl

package info (click to toggle)
snap 0.08-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 440 kB
  • ctags: 473
  • sloc: perl: 7,033; makefile: 117; sh: 70
file content (92 lines) | stat: -rw-r--r-- 1,451 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
# Gtk Import Module
#
# This module functions as a transparent Gtk wrapper around Snap.  
#

use SnapLib::HandleWrapper;

my $VERSION = "0.01";

BEGIN
{
  if (tied %handles)
    {
      $SUCCESS = 0;
      return 1;  
    }

  my $oh = $SIG{__DIE__};

  $SIG{__DIE__} = sub { return; };

  eval 
    { 
      require Gtk; 
      import Gtk; 

      require Gtk::Atoms;
      import Gtk::Atoms;

      require Gtk::Keysyms;
      import Gtk::Keysyms;
    };

  $SIG{__DIE__} = $oh;

  if ($@)
    {
      print "Error, unable to load Gtk Import module...\n";

      $SUCCESS = 0;

      return 1;
    }
  else
    {
      $SUCCESS = 1;
    }
}

return if (! $SUCCESS);

$GTK_ENABLED = init_check Gtk;

if ($GTK_ENABLED)
{
  my %temp = %handles;

  tie %handles, 'HandleWrapper', \&add_handle, \&remove_handle;

  foreach (keys %temp) { $handles{$_} = $temp{$_}; }

  push @extensions, "Gtk";
  print "Gtk Import Module $VERSION Loaded...\n";

  *main_loop = *main_gtk;  # Overwrite the main loop sub.
}
else
{
  print "Error initializing Gtk...\n";
  return;
}

sub main_gtk { main Gtk; }

sub add_handle
{
  my $data = shift;

  $data->{Tag} = Gtk::Gdk->input_add(fileno($data->{Handle}), 'read',
                                     sub { $data->{Callback}->($napster_sock,
                                                               $data->{Handle}) });
}

sub remove_handle
{
  my $data = shift;

  Gtk::Gdk->input_remove($data->{Tag});
}

1;