summaryrefslogtreecommitdiff
path: root/test/xwidget-test-manual.el
blob: 1c9b181467a4571bed05e92127870864e874de76 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
;;test like:
;; cd /path/to/xwidgets-emacs-dir
;; make   all&&  src/emacs -q --eval "(progn (load \"`pwd`/lisp/xwidget-test.el\") (xwidget-demo-basic))"


;; you should see:
;; - a gtk button
;; - a gtk toggle button
;; - a gtk slider button
;; - an xembed window(using gtk_socket) showing another emacs instance
;; - an xembed window(using gtk_socket) showing an uzbl web browser if its installed

;;the widgets will move when you type in the buffer. good!

;;there will be redrawing issues when widgets change rows, etc. bad!

;;its currently difficult to give kbd focus to the xembedded emacs,
;;but try evaling the following:

;; (xwidget-set-keyboard-grab 3 1)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; demo/test functions
(require 'xwidget)

(defmacro xwidget-demo (name &rest body)
  `(defun ,(intern (concat "xwidget-demo-" name)) ()
     (interactive)
     (switch-to-buffer ,(format "*xwidget-demo-%s*" name))
     (text-mode);;otherwise no local keymap
     (insert "Some random text for xwidgets to be inserted in for demo purposes.\n")
     ,@body))

(xwidget-demo "a-button"
              (xwidget-insert (point-min) 'Button  "button" 60  50)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-button-bidi"
              (xwidget-insert (+ 5 (point-min)) 'Button  "button" 60  50)
              (set (make-local-variable 'bidi-paragraph-direction) 'right-to-left)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))


(xwidget-demo "a-toggle-button"
              (xwidget-insert (point-min) 'ToggleButton  "toggle" 60  50)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-big-button"
              (xwidget-insert (point-min)  'Button "button" 400  500)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-socket"
              (xwidget-insert (point-min)  'socket "socket" 500  500)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-socket-osr-broken"
              (xwidget-insert (point-min)  'socket-osr "socket-osr" 500  500)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))


(xwidget-demo "a-slider"
              (xwidget-insert (point-min)  'slider "slider" 500  100)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-canvas"
              (xwidget-insert (point-min)  'cairo "canvas" 1000  1000)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-webkit-broken"
              (xwidget-insert (point-min)  'webkit "webkit" 1000  1000)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-webkit-osr"
              (xwidget-insert (point-min)  'webkit-osr "webkit-osr" 1000  1000)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic)
              (xwidget-webkit-goto-uri (xwidget-at 1) "http://www.fsf.org"))

(xwidget-demo "a-xwgir"
              (xwidget-insert (point-min)  'xwgir "xwgir" 1000  1000)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-xwgir-color-button"
              (xwgir-require-namespace "Gtk" "3.0")
              (put 'ColorButton :xwgir-class '("Gtk" "ColorSelection" "new"))
              (xwidget-insert (point-min)  'ColorButton "xwgir-color-button" 1000  1000)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-xwgir-button"
              (xwgir-require-namespace "Gtk" "3.0")
              (put 'xwgirButton :xwgir-class '("Gtk" "Button" "new"))

              (xwidget-insert (point-min)  'xwgirButton "xwgir label didnt work..." 700  700)
              (xwgir-xwidget-call-method (xwidget-at 1) "set_label" '( "xwgir label worked!"))
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-xwgir-button-constructor"
              (xwgir-require-namespace "Gtk" "3.0")
              (put 'xwgirButtonLabel :xwgir-class '("Gtk" "Button" "new_with_label"))

              (xwidget-insert (point-min)  'xwgirButtonLabel "xwgir label didnt work..." 700  700 '("constructor label worked!"))
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))


(xwidget-demo "a-xwgir-check-button"
              (xwgir-require-namespace "Gtk" "3.0")
              (put 'xwgirCheckButton :xwgir-class '("Gtk" "CheckButton" "new"))

              (xwidget-insert (point-min)  'xwgirCheckButton "xwgir label didnt work..." 700  700)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-xwgir-hscale-broken"
              (xwgir-require-namespace "Gtk" "3.0")
              (put 'xwgirHScale :xwgir-class '("Gtk" "HScale" "new_with_range" ))

              (xwidget-insert (point-min)  'xwgirHScale "xwgir label didnt work..." 700  700 '(0.0 100.0 1.0))
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))

(xwidget-demo "a-xwgir-webkit"
              (xwgir-require-namespace "WebKit" "3.0")
              (put 'xwgirWebkit :xwgir-class '("WebKit" "WebView"))

              (xwidget-insert (point-min)  'xwgirWebkit "xwgir webkit..." 700  700)
              (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic))



;; tentative testcase:
;; (xwgir-require-namespace "WebKit" "3.0")

;; (put 'webkit-osr :xwgir-class '("WebKit" "WebView"))
;; (xwgir-call-method (xwidget-at 1) "set_zoom_level" '(3.0))

;; (xwgir-require-namespace "Gtk" "3.0")
;; (put 'color-selection :xwgir-class '("Gtk" "ColorSelection"))


(xwidget-demo "basic"
  (xwidget-insert (point-min)  'button "button" 40  50 )
  (xwidget-insert          15  'toggle "toggle" 60  30  )
  (xwidget-insert          30  'socket "emacs"  400 200 )
  (xwidget-insert          20  'slider "slider" 100 50  )
  (xwidget-insert          40  'socket "uzbl-core"   400 400 )
  (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-basic)
)


;it doesnt seem gtk_socket_steal works very well. its deprecated.
; xwininfo -int
; then (xwidget-embed-steal 3 <winid>)
(defun xwidget-demo-grab ()
  (interactive)
  (insert "0 <<< grabbed appp will appear here\n")
  (xwidget-insert          1 1 3 "1" 1000 )
  (define-key (current-local-map) [xwidget-event] 'xwidget-handler-demo-grab)
  )

;ive basically found these xembeddable things:
;openvrml
;emacs
;mplayer
;surf
;uzbl

;try the openvrml:
;/usr/libexec/openvrml-xembed 0 ~/Desktop/HelloWorld.wrl

(defun xwidget-handler-demo-basic ()
  (interactive)
  (message "stuff happened to xwidget %S" last-input-event)
  (let*
      ((xwidget-event-type (nth 1 last-input-event))
       (xwidget (nth 2 last-input-event)))
    (cond ( (eq xwidget-event-type 'xembed-ready)
            (let*
                ((xembed-id (nth 3 last-input-event)))
              (message "xembed ready  event: %S xw-id:%s" xembed-id xwidget)
              ;;will start emacs/uzbl in a xembed socket when its ready
              (cond
               (t;;(eq 3 xwidget)
                (start-process "xembed" "*xembed*" "/var/lib/jenkins/jobs/emacs-xwidgets-automerge/workspace/src/emacs" "-q" "--parent-id" (number-to-string xembed-id) ) )
;;               ((eq 5 xwidget-id)
;;                (start-process "xembed2" "*xembed2*" "uzbl-core"  "-s" (number-to-string xembed-id)  "http://www.fsf.org" )
               )

               )
            ))))



(defun xwidget-handler-demo-grab ()
  (interactive)
  (message "stuff happened to xwidget %S" last-input-event)
  (let*
      ((xwidget-event-type (nth 2 last-input-event)))
    (cond ( (eq xwidget-event-type 'xembed-ready)
            (let*
                ((xembed-id (nth 3 last-input-event)))
              (message "xembed ready  %S" xembed-id)
              )
            ))))
(defun xwidget-dummy-hook ()
  (message "xwidget dummy hook called"))

;  (xwidget-resize-hack 1 200 200)

;(xwidget-demo-basic)

(provide 'xwidget-test-manual)