step by step to write a gnome-shell extension

40
手把手教你寫 GNOME shell 擴充套件 tools, hollyladd, by-nc-nd Preview

Upload: yuren-ju

Post on 12-May-2015

14.448 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: step by step to write a gnome-shell extension

手把手教你寫GNOME shell

擴充套件tools, hollyladd, by-nc-nd

Preview

Page 2: step by step to write a gnome-shell extension

即時討論https://convore.com/gnome-taiwan/gnome-shell/

or 短網址http://j.mp/gs-ext

Page 3: step by step to write a gnome-shell extension

簡報作者

● Yuren Ju <[email protected]>● Blog: Yuren's Info Area● 社群: Hacking Thursday

Page 4: step by step to write a gnome-shell extension
Page 5: step by step to write a gnome-shell extension

gnome-shell include...● GNOME3 user experience desktop● Shell Tookit (similar GTK+)● More...

Page 6: step by step to write a gnome-shell extension

Web Browser extension

Page 7: step by step to write a gnome-shell extension

Important!

You can write gnome-shell extension with

Javascript!

Page 8: step by step to write a gnome-shell extension

How

Gnome-shell core

GObject Introspection

Gnome-shell widgets

C Launguage

Javascript

<interface>

Page 9: step by step to write a gnome-shell extension

How?

Gnome-shell core

Gobject Introspection (GI)

Gobject-based library

overview workspace calendar extension...

gnome-shell widgets

Page 10: step by step to write a gnome-shell extension

GObject Introspection

Native C API

GI

JS Java Python Perl Ruby PHP?

GStreamerVTE notifyGTK Clutter

Page 11: step by step to write a gnome-shell extension

Getting started!

$ gnome-shell-extension-tool --create-extension

LiveUSBhttp://gnome3.org/tryit.html

Page 12: step by step to write a gnome-shell extension

Create extension

Page 13: step by step to write a gnome-shell extension

Restart gnome-shell

alt+F2 and press "r"

Page 14: step by step to write a gnome-shell extension

Default extensionClick panel

Show Hello world, and destroy after 5sec

Page 15: step by step to write a gnome-shell extension

Default extension code// Sample extension code, makes clicking on the panel show a messageconst St = imports.gi.St;const Mainloop = imports.mainloop;

const Main = imports.ui.main;

function _showHello() { let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" }); let monitor = global.get_primary_monitor(); global.stage.add_actor(text); text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2)); Mainloop.timeout_add(3000, function () { text.destroy(); });}

// Put your extension initialization code herefunction main() { Main.panel.actor.reactive = true; Main.panel.actor.connect('button-release-event', _showHello);}

Page 16: step by step to write a gnome-shell extension

Global (1/2)● Monitor

● get_monitors()● get_primary_monito

r()● get_primary_monito

r_index()● get_focus_monitor()

● Pointer:● get_pointer()

● Window/Screen:● get_gdk_screen()● get_screen()● get_window_actors()

return MetaRectangle

Page 17: step by step to write a gnome-shell extension

Global (2/2)● Properties

● stage● screen-width/screen-height● window-group● settings● datadir● userdatadir

Page 18: step by step to write a gnome-shell extension

Looking glass

alt+F2 and press "lg"

Page 19: step by step to write a gnome-shell extension

Default extension code// Sample extension code, makes clicking on the panel show a messageconst St = imports.gi.St;const Mainloop = imports.mainloop;

const Main = imports.ui.main;

function _showHello() { let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" }); let monitor = global.get_primary_monitor(); global.stage.add_actor(text); text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2)); Mainloop.timeout_add(3000, function () { text.destroy(); });}

// Put your extension initialization code herefunction main() { Main.panel.actor.reactive = true; Main.panel.actor.connect('button-release-event', _showHello);}

http://library.gnome.org/devel/glib/unstable/glib-The-Main-Event-Loop.html

Page 20: step by step to write a gnome-shell extension

Main

Page 21: step by step to write a gnome-shell extension

Main● Main.panel

● button● _leftBox, _centerBox, _rightBox● _dateMenu● ...

● Main.overview● Main.runDialog● Main.uiGroup● ...

Page 22: step by step to write a gnome-shell extension

Default extension code// Sample extension code, makes clicking on the panel show a messageconst St = imports.gi.St;const Mainloop = imports.mainloop;

const Main = imports.ui.main;

function _showHello() { let text = new St.Label({ style_class: 'helloworld-label', text: "Hello, world!" }); let monitor = global.get_primary_monitor(); global.stage.add_actor(text); text.set_position(Math.floor (monitor.width / 2 - text.width / 2), Math.floor(monitor.height / 2 - text.height / 2)); Mainloop.timeout_add(3000, function () { text.destroy(); });}

// Put your extension initialization code herefunction main() { Main.panel.actor.reactive = true; Main.panel.actor.connect('button-release-event', _showHello);}

Page 23: step by step to write a gnome-shell extension

Try it● Main.panel._dateMenu.menu.actor.set_opacity(100)● Main.panel._dateMenu.actor.set_scale(1.5, 1.5)● Main.panel._dateMenu.menu.actor.set_z_rotation_from_

gravity(45.0, Clutter.Gravity.CENTER)● Don's you like status-menu?

● Main.panel._statusmenu.actor.hide()

Page 24: step by step to write a gnome-shell extension

Example extension – fancy screenshot tool

$ sudo zypper refresh && sudo zypper install ImageMagick(Because GdkPixbuf.savev function is broken)

http://www.youtube.com/watch?v=epKssSQpfLQ

Page 25: step by step to write a gnome-shell extension

Step 1: PanelButton

Page 26: step by step to write a gnome-shell extension

_leftBox _centerBox _rightBox

Page 27: step by step to write a gnome-shell extension

Step 2: PopupMenu

Page 28: step by step to write a gnome-shell extension

Step 3: Handle Click

Page 29: step by step to write a gnome-shell extension

Tweener● transition

● linear, easeInQuad, … (reference python-clutter)

● onComplete/onCompleteScope● scale_x, scale_y, opacity

Page 30: step by step to write a gnome-shell extension

Animation

Counting down

Shotting

Zoom

Page 31: step by step to write a gnome-shell extension

Step 4: Animation (1/3)

Page 32: step by step to write a gnome-shell extension

Step 4: Animation (2/3)

Page 33: step by step to write a gnome-shell extension

Step 4: Animation (3/3)

Page 34: step by step to write a gnome-shell extension

Step 5: Save screenshot

Page 35: step by step to write a gnome-shell extension

https://gist.github.com/9c29efaa9b00a75db81f

Source Code

Page 36: step by step to write a gnome-shell extension

Big issue!

Page 37: step by step to write a gnome-shell extension

No documentsad...

Sad Zeb, by-nc,sa

Page 38: step by step to write a gnome-shell extension

Reference● gnome-shell source code● mutter source code● http://git.gnome.org/browse/● ZZzzzz

Page 39: step by step to write a gnome-shell extension

We need you!

Page 40: step by step to write a gnome-shell extension

Q & ASlides Download

http://j.mp/gs-ext-slides