Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions xkcd@rjanja/files/xkcd@rjanja/desklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const Util = imports.misc.util;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Cogl = imports.gi.Cogl;

const Pango = imports.gi.Pango;
const Tooltips = imports.ui.tooltips;
const PopupMenu = imports.ui.popupMenu;
const Cinnamon = imports.gi.Cinnamon;
const Soup = imports.gi.Soup

let session
if (Soup.get_major_version() == "2") {
session = new Soup.SessionAsync();
Expand Down Expand Up @@ -164,6 +166,8 @@ MyDesklet.prototype = {
catch (e) {}
}

this._altTextLabel.set_text(this.curXkcd.alt); // Set alt text

this.set_tooltip(null);

let imgFilename = this.save_path + '/' + this.curXkcd.num + '.png';
Expand Down Expand Up @@ -218,11 +222,34 @@ MyDesklet.prototype = {

this.setHeader(_("xkcd"));

// Create container for image and alt text
this._mainBox = new St.BoxLayout({ vertical: true });

this._image = new Clutter.Image();
this._imageFrame = new Clutter.Actor({width: 0, height: 0})
this._imageFrame.set_content(this._image)
this.setContent(this._imageFrame)
//this.setContent(this._imageFrame)

// Add textbox to Image Frame
this._mainBox.add_actor(this._imageFrame);

// Label for alt text
this._altTextLabel = new St.Label({
text: "",
style_class: "xkcd-alt-text",
x_align: Clutter.ActorAlign.FILL,
y_align: Clutter.ActorAlign.START
});

// Enable text wrapping on the underlying Clutter.Text
this._altTextLabel.clutter_text.set_line_wrap(true);
this._altTextLabel.clutter_text.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR);
this._altTextLabel.clutter_text.set_ellipsize(Pango.EllipsizeMode.NONE);

this._mainBox.add_actor(this._altTextLabel);

this.setContent(this._mainBox);

this._menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this._menu.addAction(_("View latest xkcd"), function () {
this.refresh(null);
Expand Down Expand Up @@ -325,4 +352,4 @@ MyDesklet.prototype = {
function main(metadata, desklet_id){
let desklet = new MyDesklet(metadata);
return desklet;
}
}
7 changes: 7 additions & 0 deletions xkcd@rjanja/files/xkcd@rjanja/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
border: 2px solid #96A8C8;
background-color: rgba(150, 168, 200, 0.7);
border-radius: 5px;
}

.xkcd-alt-text {
white-space: normal;
word-wrap: break-word;
/* Optionally, define a max-width so the label knows when to wrap */
max-width: 300px;
}