~kokoto-java/kazam/depencie-and-stuff

« back to all changes in this revision

Viewing changes to kazam/backend/grabber.py

  • Committer: David Klasinc
  • Date: 2012-11-11 19:36:05 UTC
  • mfrom: (193.2.82 unstable)
  • Revision ID: bigwhale@lubica.net-20121111193605-vh3fxglxwfhyh8ne
Merged from unstable branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        logger.debug("Starting Grabber.")
48
48
 
49
49
 
50
 
    def setup_sources(self, video_source, area, xid):
 
50
    def setup_sources(self, video_source, area, xid, active = False, god = False):
51
51
        self.video_source = video_source
52
52
        self.area = area
53
53
        self.xid = xid
 
54
        self.god = god
 
55
        if active:
 
56
            from gi.repository import GdkX11
 
57
            active_win = HW.default_screen.get_active_window()
 
58
            self.xid = GdkX11.X11Window.get_xid(active_win)
54
59
 
55
60
        logger.debug("Grabber source: {0}, {1}, {2}, {3}".format(self.video_source['x'],
56
61
                                                                 self.video_source['y'],
66
71
        #
67
72
        # Rewrite this, because it sucks
68
73
        #
69
 
        soundfile = os.path.join(prefs.datadir, 'sounds', prefs.sound_files[prefs.shutter_type])
70
 
        subprocess.call(['/usr/bin/canberra-gtk-play', '-f', soundfile])
 
74
        if prefs.shutter_sound and (not self.god):
 
75
            soundfile = os.path.join(prefs.datadir, 'sounds', prefs.sound_files[prefs.shutter_type])
 
76
            subprocess.call(['/usr/bin/canberra-gtk-play', '-f', soundfile])
71
77
 
72
78
        if self.xid:
73
 
            win = GdkX11.X11Window.foreign_new_for_display(disp, self.xid)
74
 
            (x, y, w, h) = win.get_geometry()
 
79
            if prefs.capture_borders_pic:
 
80
                app_win = GdkX11.X11Window.foreign_new_for_display(disp, self.xid)
 
81
                (rx, ry, rw, rh) = app_win.get_geometry()
 
82
                area = app_win.get_frame_extents()
 
83
                (fx, fy, fw, fh) = (area.x, area.y, area.width, area.height)
 
84
                win = Gdk.get_default_root_window()
 
85
                logger.debug("Coordinates RX {0} RY {1} RW {2} RH {3}".format(rx, ry, rw, rh))
 
86
                logger.debug("Coordinates FX {0} FY {1} FW {2} FH {3}".format(fx, fy, fw, fh))
 
87
                dx = fw - rw
 
88
                dy = fh - rh
 
89
                (x, y, w, h) = (fx, fy, fw, fh)
 
90
                logger.debug("Coordinates delta: DX {0} DY {1}".format(dx, dy))
 
91
            else:
 
92
                win = GdkX11.X11Window.foreign_new_for_display(disp, self.xid)
 
93
                (x, y, w, h) = win.get_geometry()
75
94
        else:
76
95
            win = Gdk.get_default_root_window()
77
96
            (x, y, w, h) = (self.video_source['x'],
79
98
                            self.video_source['width'],
80
99
                            self.video_source['height'])
81
100
 
 
101
        logger.debug("Coordinates X {0} Y {1} W {2} H {3}".format(x, y, w, h))
82
102
        self.pixbuf = Gdk.pixbuf_get_from_window(win, x, y, w, h)
83
103
 
84
104
        if prefs.capture_cursor_pic:
 
105
            logger.debug("Adding cursor.")
 
106
 
85
107
            cursor = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), Gdk.CursorType.LEFT_PTR)
86
108
            c_picbuf = Gdk.Cursor.get_image(cursor)
87
 
            pointer = win.get_device_position(pntr_device)
88
 
            c_picbuf.composite(self.pixbuf, x, y, w, h,
89
 
                                            pointer[1],
90
 
                                            pointer[2],
91
 
                                            1.0,
92
 
                                            1.0,
93
 
                                            GdkPixbuf.InterpType.BILINEAR,
94
 
                                            255)
 
109
 
 
110
            if self.xid and prefs.capture_borders_pic:
 
111
                pointer = app_win.get_device_position(pntr_device)
 
112
                (px, py) = (pointer[1], pointer[2])
 
113
                c_picbuf.composite(self.pixbuf, rx, ry, rw, rh,
 
114
                                   px + dx - 6,
 
115
                                   py + dy - 2,
 
116
                                   1.0,
 
117
                                   1.0,
 
118
                                   GdkPixbuf.InterpType.BILINEAR,
 
119
                                   255)
 
120
            else:
 
121
                pointer = win.get_device_position(pntr_device)
 
122
                (px, py) = (pointer[1], pointer[2])
 
123
                #
 
124
                # Cursor is offseted by 6 pixels to the right and 2 down
 
125
                #
 
126
                c_picbuf.composite(self.pixbuf, x, y, w, h,
 
127
                                   px - 6,
 
128
                                   py - 2,
 
129
                                   1.0,
 
130
                                   1.0,
 
131
                                   GdkPixbuf.InterpType.BILINEAR,
 
132
                                   255)
 
133
 
 
134
            logger.debug("Cursor coords: {0} {1}".format(px, py))
95
135
 
96
136
        if self.area is not None:
 
137
            logger.debug("Cropping image.")
97
138
            self.area_buf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, self.area[4], self.area[5])
98
139
            self.pixbuf.copy_area(self.area[0], self.area[1], self.area[4], self.area[5], self.area_buf, 0, 0)
99
140
            self.pixbuf = None