Starts uzbl process and connects to its control socket
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 06 Jun 2011 17:41:38 +0000
changeset 3 32456ba40192
parent 2 7e604e6f195e
child 4 385102f5bf00
Starts uzbl process and connects to its control socket
WebKitRenderer.st
WebKitView.st
--- a/WebKitRenderer.st	Fri Jun 03 08:54:52 2011 +0000
+++ b/WebKitRenderer.st	Mon Jun 06 17:41:38 2011 +0000
@@ -1,7 +1,7 @@
 "{ Package: 'stx:libwebkit' }"
 
 Object subclass:#WebKitRenderer
-	instanceVariableNames:'view in out'
+	instanceVariableNames:'view pid connection'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-WebKit'
@@ -12,12 +12,48 @@
 
 for: aWebKitView
 
-    self new initializeForView: aWebKitView
+    ^self new initializeForView: aWebKitView
 
     "Created: / 02-06-2011 / 23:38:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2011 / 10:38:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!WebKitRenderer methodsFor:'initialization'!
+!WebKitRenderer methodsFor:'event loop'!
+
+dispatchEvent
+
+    | event |
+    connection atEnd ifTrue:[^self].
+    event := connection nextLine.
+    event ifNil:[^self].
+    Transcript showCR: event.
+
+    "Created: / 06-06-2011 / 18:13:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+eventLoop
+
+    [ connection atEnd ] whileFalse: [
+        self dispatchEvent 
+    ]
+
+    "Created: / 06-06-2011 / 18:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!WebKitRenderer methodsFor:'initialization & release'!
+
+close
+    self shouldImplement
+
+    "Created: / 06-06-2011 / 18:38:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+init
+
+    connection nextPutAll:'set uri = http://www.webkit.org'; cr.
+
+    "Created: / 06-06-2011 / 18:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
 initializeForView: aWebKitView
 
@@ -26,30 +62,60 @@
     "Created: / 02-06-2011 / 23:38:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!WebKitRenderer methodsFor:'spawn/terminate renderer'!
+!WebKitRenderer methodsFor:'private'!
 
-spawnRenderer
+startEventLoop
+    
+    [ 
+        self waitFor; init; eventLoop; close
+    ] fork
+
+    "Created: / 06-06-2011 / 17:57:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
-    | inPipe outPipe |
-    inPipe := NonPositionableExternalStream makePipe.
-    outPipe := NonPositionableExternalStream makePipe.
+waitFor
+
+    | client |
+
+    connection listenFor: 1.
+    client := connection accept.
+    connection port asFilename remove.
+    connection close.
+    connection := client.
+
+    "Created: / 06-06-2011 / 18:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
-    self halt:'Unfinished'.
+!WebKitRenderer methodsFor:'spawn / terminate'!
+
+spawn
+    |path uzbl args|
 
-    OperatingSystem
-        exec: '/home/jv/work/uzbl/uzbl-core'
-        withArguments: #('/home/jv/work/uzbl/uzbl-core' '-c' '-' '-p' '-s')
-        environment: nil
-        fileDescriptors: #(1 2 3)
-        fork: true
-        newPgrp: false
-        inDirectory: Filename defaultDirectory pathName
+    path := Filename newTemporary.
+    connection := Socket newUNIXserverAt:path pathName.
+    uzbl := '/home/jv/work/uzbl/uzbl-core'.
+    args := (Array 
+                with:'/home/jv/work/uzbl/uzbl-core'
+                with:'-s'
+                with:view rendererView embeddingWindowId
+                with:'--connect-socket=' , path pathName).
+     "pid := OperatingSystem
+     exec: uzbl
+     withArguments: args
+     environment: nil
+     fileDescriptors: #(1 2 3)
+     fork: true
+     newPgrp: false
+     inDirectory: path directory pathName
+    "
+    self halt.
+    self startEventLoop.
 
     "Created: / 02-06-2011 / 23:40:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2011 / 18:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-terminateRenderer
-
+terminate
     "Created: / 02-06-2011 / 23:40:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
--- a/WebKitView.st	Fri Jun 03 08:54:52 2011 +0000
+++ b/WebKitView.st	Mon Jun 06 17:41:38 2011 +0000
@@ -40,6 +40,12 @@
     "Created: / 03-06-2011 / 09:40:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!WebKitView methodsFor:'accessing'!
+
+rendererView
+    ^ rendererView
+! !
+
 !WebKitView methodsFor:'accessing - classes'!
 
 rendererClass
@@ -115,25 +121,26 @@
     "Modified: / 02-06-2011 / 23:45:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!WebKitView methodsFor:'initialization'!
+!WebKitView methodsFor:'initialization & release'!
 
 initialize
     super initialize.
     renderer := self rendererClass for:self.
     rendererView := XEmbedContainerView in: self.
     rendererView origin: 0.0@0.0 corner: 1.0@1.0.
+    rendererView useWorkaround: #uzbl.
 
     "Created: / 02-06-2011 / 23:46:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-06-2011 / 09:39:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2011 / 18:11:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !WebKitView methodsFor:'realization'!
 
-preRealize
+postRealize
+    super postRealize.
+    renderer spawn.
 
-    super preRealize
-
-    "Created: / 02-06-2011 / 23:33:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 06-06-2011 / 10:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !WebKitView class methodsFor:'documentation'!