Skip to content

Commit

Permalink
middle click to change font size
Browse files Browse the repository at this point in the history
  • Loading branch information
biji committed Jul 15, 2017
1 parent 9087a86 commit 87a9d9c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Simply showing network speed. Left click to change modes:
1. Up & down speed in Bytes per second
1. Total of downloaded in Bytes (Right click to reset counter)

Middle click to change font size
42 changes: 26 additions & 16 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ let settings;
let button, timeout;
// let icon, iconDark;
let ioSpeed;
let ioSpeedW;
let lbl;
let lastCount = 0, lastSpeed = 0, lastCountUp = 0;
let mode; // 0: kbps 1: K/s 2: U:kbps D:kbps 3: U:K/s D:K/s 4: Total KB
let fontmode;
let resetNextCount = false, resetCount = 0;

function init() {

settings = Convenience.getSettings(PREFS_SCHEMA);

mode = settings.get_int('mode'); // default mode using bit (bps, kbps)
fontmode = settings.get_int('fontmode');

button = new St.Bin({
style_class: 'panel-button',
Expand All @@ -50,11 +50,6 @@ function init() {
style_class: 'simplenetspeed-label'
});

ioSpeedW = new St.Label({
text: '---',
style_class: 'simplenetspeed-label-w'
});

// ioSpeedStaticIcon = new St.Label({
// text: '💾',
// style_class: 'simplenetspeed-static-icon'
Expand All @@ -70,8 +65,16 @@ function changeMode(widget, event) {
resetNextCount = true;
parseStat();
}
else if (event.get_button() == 1)
{
else if (event.get_button() == 2) { // change font
fontmode++;
if (fontmode > 3) {
fontmode=0;
}
settings.set_int('fontmode', fontmode);
button.set_child(chooseLabel());
parseStat();
}
else if (event.get_button() == 1) {
mode++;
if (mode > 4) {
mode = 0;
Expand All @@ -80,16 +83,23 @@ function changeMode(widget, event) {
button.set_child(chooseLabel());
parseStat();
}
log('mode:' + mode + ' font:' + fontmode);
}

function chooseLabel() {
if (mode == 0 || mode == 1 || mode == 4) {
lbl=ioSpeed;
styleName = 'simplenetspeed-label';
}
else {
lbl=ioSpeedW;
styleName = 'simplenetspeed-label-w';
}
return lbl;

if (fontmode > 0) {
styleName = styleName + '-' + fontmode;
}

ioSpeed.set_style_class_name(styleName);
return ioSpeed;
}

function parseStat() {
Expand Down Expand Up @@ -135,24 +145,24 @@ function parseStat() {
}

if (mode >= 0 && mode <= 1) {
lbl.set_text(dot + speedToString(speed));
ioSpeed.set_text(dot + speedToString(speed));
}
else if (mode >= 2 && mode <= 3) {
lbl.set_text("↓" + speedToString(speed - speedUp) + " ↑" + speedToString(speedUp));
ioSpeed.set_text("↓" + speedToString(speed - speedUp) + " ↑" + speedToString(speedUp));
}
else if (mode == 4) {
if (resetNextCount == true) {
resetNextCount = false;
resetCount = count;
}
lbl.set_text("∑ " + speedToString(count - resetCount));
ioSpeed.set_text("∑ " + speedToString(count - resetCount));
}

lastCount = count;
lastCountUp = countUp;
lastSpeed = speed;
} catch (e) {
lbl.set_text(e.message);
ioSpeed.set_text(e.message);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_generated": "Generated by SweetTooth, do not edit",
"description": "Simply showing network speed. Click to change mode",
"description": "Simply showing network speed. Left click to change modes:\n\n1. Total net speed in bits per second\n2. Total net speed in Bytes per second\n3. Up & down speed in bits per second\n4. Up & down speed in Bytes per second\n5. Total of downloaded in Bytes (Right click to reset counter)\n\nMiddle click to change font size",
"name": "Simple net speed",
"shell-version": [
"3.14",
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
4 changes: 4 additions & 0 deletions schemas/org.gnome.shell.extensions.simplenetspeed.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
<range min="0" max="4" />
<default>0</default>
</key>
<key name="fontmode" type="i">
<range min="0" max="3" />
<default>0</default>
</key>
</schema>
</schemalist>
54 changes: 52 additions & 2 deletions stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
.simplenetspeed-label {
width: 70px;
text-align: right;
margin-left: 2px;
margin-left: 1px;
margin-right: 2px;
font-size: 1em;
}

.simplenetspeed-label-w {
width: 120px;
text-align: right;
margin-left: 2px;
margin-left: 1px;
margin-right: 1px;
font-size: 1em;
}

.simplenetspeed-label-1 {
width: 70px;
text-align: right;
margin-left: 1px;
margin-right: 2px;
font-size: .8em;
}

.simplenetspeed-label-w-1 {
width: 120px;
text-align: right;
margin-left: 1px;
margin-right: 1px;
font-size: .8em;
}

.simplenetspeed-label-2 {
width: 70px;
text-align: right;
margin-left: 1px;
margin-right: 2px;
font-size: .9em;
}

.simplenetspeed-label-w-2 {
width: 120px;
text-align: right;
margin-left: 1px;
margin-right: 1px;
font-size: .9em;
}

.simplenetspeed-label-3 {
width: 80px;
text-align: right;
margin-left: 1px;
margin-right: 2px;
font-size: 1.1em;
}

.simplenetspeed-label-w-3 {
width: 135px;
text-align: right;
margin-left: 1px;
margin-right: 1px;
font-size: 1.1em;
}

/*.simplenetspeed-static-icon {
Expand Down

1 comment on commit 87a9d9c

@biji
Copy link
Owner Author

@biji biji commented on 87a9d9c Jul 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8

Please sign in to comment.