Skip to content
Permalink
Browse files

support pop window, such as emacs-china.org

  • Loading branch information...
manateelazycat committed Jul 21, 2018
1 parent 109f754 commit 0fddf6d39ab768066857c6c5dffdb87550f347df
Showing with 73 additions and 10 deletions.
  1. +12 −2 core/browser.py
  2. +19 −3 eaf.el
  3. +42 −5 eaf.py
@@ -41,6 +41,9 @@ def __init__(self):
self.web_page = BrowserPage()
self.setPage(self.web_page)

def createWindow(self, window_type):
return self.create_new_browser_window_callback()

def event(self, event):
if event.type() == QEvent.ChildAdded:
obj = event.child()
@@ -55,15 +58,21 @@ def eventFilter(self, obj, event):
clicked_url = hit.linkUrl()
base_url = hit.baseUrl()

if clicked_url != base_url and clicked_url != '':

if clicked_url != None and base_url != None and clicked_url != base_url and clicked_url != '':
result = ""

if 'http://' in clicked_url or 'https://' in clicked_url:
result = clicked_url
elif clicked_url == "#":
result = base_url + clicked_url
else:
# Don't open url in EAF if clicked_url is not start with http/ftp or #
result = "http://" + base_url.split("/")[2] + clicked_url

event.accept()
return False

modifiers = QApplication.keyboardModifiers()

if modifiers != Qt.ControlModifier:
@@ -76,7 +85,8 @@ def eventFilter(self, obj, event):
return True

event.accept()
return True
return False

elif event.type() == QEvent.MouseButtonPress:
if event.button() == MOUSE_FORWARD_BUTTON:
self.forward()
22 eaf.el
@@ -219,14 +219,14 @@ We need calcuate render allocation to make sure no black border around render co
(list x y w h)))

(defun eaf-generate-id ()
(format "%04x%04x-%04x-%04x-%04x-%06x%06x"
(format "%04x-%04x-%04x-%04x-%04x-%04x-%04x"
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 6))
(random (expt 16 6)) ))
(random (expt 16 4))
(random (expt 16 4)) ))

(defun eaf-create-buffer (input-content)
(let ((eaf-buffer (generate-new-buffer (truncate-string-to-width input-content eaf-title-length))))
@@ -394,6 +394,22 @@ We need calcuate render allocation to make sure no black border around render co
)
))))))))

(dbus-register-signal
:session "com.lazycat.eaf" "/com/lazycat/eaf"
"com.lazycat.eaf" "create_new_browser_buffer"
'eaf-create-new-browser-buffer)

(defun eaf-create-new-browser-buffer (new-window-buffer-id)
(let ((eaf-buffer (generate-new-buffer (concat "browser popup window " new-window-buffer-id))))
(with-current-buffer eaf-buffer
(eaf-mode)
(read-only-mode)
(set (make-local-variable 'buffer-id) new-window-buffer-id)
(set (make-local-variable 'buffer-url) "")
(set (make-local-variable 'buffer-app-name) "browser")
)
(switch-to-buffer eaf-buffer)))

(dbus-register-signal
:session "com.lazycat.eaf" "/com/lazycat/eaf"
"com.lazycat.eaf" "focus_emacs_buffer"
47 eaf.py
@@ -74,22 +74,49 @@ def scroll_buffer(self, view_info, scroll_direction, scroll_type):
if buffer_id in self.buffer_dict:
self.buffer_dict[buffer_id].scroll(scroll_direction, scroll_type)

def get_new_browser_window_buffer_id(self):
import secrets

return "{0}-{1}-{2}-{3}-{4}-{5}-{6}".format(
secrets.token_hex(2),
secrets.token_hex(2),
secrets.token_hex(2),
secrets.token_hex(2),
secrets.token_hex(2),
secrets.token_hex(2),
secrets.token_hex(2))

def create_new_browser_window(self):
# Generate buffer id same as eaf.el does.
buffer_id = self.get_new_browser_window_buffer_id()

# Create buffer for create new browser window.
app_buffer = self.create_buffer(buffer_id, "http://0.0.0.0", "app.browser.buffer")

# Create emacs buffer with buffer id.
self.create_new_browser_buffer(buffer_id)

# Return new QWebEngineView for create new browser window.
return app_buffer.buffer_widget

def create_app(self, buffer_id, url, module_path):
try:
module = importlib.import_module(module_path)
buf = module.AppBuffer(buffer_id, url)
buf.module_path = module_path
self.create_buffer(buffer_id, buf)
self.create_buffer(buffer_id, url, module_path)

return ""
except ImportError:
import traceback
traceback.print_exc()
return "Something wrong when import {0}".format(module_path)

def create_buffer(self, buffer_id, app_buffer):
def create_buffer(self, buffer_id, url, module_path):
global emacs_width, emacs_height

# Create application buffer.
module = importlib.import_module(module_path)
app_buffer = module.AppBuffer(buffer_id, url)
app_buffer.module_path = module_path

# Add buffer to buffer dict.
self.buffer_dict[buffer_id] = app_buffer

@@ -104,9 +131,15 @@ def create_buffer(self, buffer_id, app_buffer):
# Send message to emacs.
app_buffer.input_message.connect(self.input_message)

# Add create new window callback if module is browser
if module_path == "app.browser.buffer":
app_buffer.buffer_widget.create_new_browser_window_callback = self.create_new_browser_window

# Restore buffer session.
self.restore_buffer_session(app_buffer)

return app_buffer

@dbus.service.method(EAF_DBUS_NAME, in_signature="s", out_signature="")
def update_views(self, args):
global emacs_xid
@@ -218,6 +251,10 @@ def open_buffer_url(self, url):
def input_message(self, buffer_id, message, callback_type):
pass

@dbus.service.signal("com.lazycat.eaf")
def create_new_browser_buffer(self, buffer_id):
pass

def save_buffer_session(self, buf):
# Create config file it not exist.
if not os.path.exists(self.session_file_path):

0 comments on commit 0fddf6d

Please sign in to comment.
You can’t perform that action at this time.