-
Notifications
You must be signed in to change notification settings - Fork 135
Clock position #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
slackhead
wants to merge
5
commits into
xorg62:master
Choose a base branch
from
slackhead:positioning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Clock position #57
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,11 @@ init(void) | |
} | ||
clearok(ttyclock->datewin, True); | ||
|
||
set_center(ttyclock->option.center); | ||
if (ttyclock->option.center) | ||
set_center(ttyclock->option.center); | ||
else | ||
if (ttyclock->option.position) | ||
set_position(ttyclock->option.position); | ||
|
||
nodelay(stdscr, True); | ||
|
||
|
@@ -375,7 +379,10 @@ set_second(void) | |
|
||
clock_move(ttyclock->geo.x, (ttyclock->geo.y - y_adj), new_w, ttyclock->geo.h); | ||
|
||
set_center(ttyclock->option.center); | ||
if (ttyclock->option.center) | ||
set_center(ttyclock->option.center); | ||
else | ||
if (ttyclock->option.position) | ||
|
||
return; | ||
} | ||
|
@@ -396,6 +403,34 @@ set_center(Bool b) | |
return; | ||
} | ||
|
||
void | ||
set_position(int p) | ||
{ | ||
int LINE, COL; | ||
|
||
ttyclock->option.rebound = False; | ||
|
||
if (p >= 1 && p <= 3) | ||
LINE = 0; | ||
if (p >= 4 && p <= 6) | ||
LINE = (LINES / 2) - (ttyclock->geo.h / 2); | ||
if (p >= 7 && p <= 9) | ||
LINE = LINES - ttyclock->geo.h - 2; | ||
|
||
if (p == 1 || p == 4 || p == 7) | ||
COL = 0; | ||
if (p == 2 || p == 5 || p == 8) | ||
COL = (COLS / 2) - (ttyclock->geo.w / 2); | ||
if (p == 3 || p == 6 || p == 9) | ||
COL = COLS - ttyclock->geo.w; | ||
|
||
clock_move(LINE, | ||
COL, | ||
ttyclock->geo.w, | ||
ttyclock->geo.h); | ||
|
||
} | ||
|
||
void | ||
set_box(Bool b) | ||
{ | ||
|
@@ -423,6 +458,9 @@ void | |
key_event(void) | ||
{ | ||
int i, c; | ||
int p = 0; | ||
char nums[11] = {'"','!','@','#','$','%','^','&','*','(','\0'}; | ||
wchar_t gbp = L'£'; | ||
|
||
struct timespec length = { ttyclock->option.delay, ttyclock->option.nsdelay }; | ||
|
||
|
@@ -448,7 +486,10 @@ key_event(void) | |
} | ||
|
||
|
||
switch(c = wgetch(stdscr)) | ||
c = wgetch(stdscr); | ||
if (c == gbp) | ||
c = '#'; | ||
switch(c) | ||
{ | ||
case KEY_UP: | ||
case 'k': | ||
|
@@ -523,6 +564,21 @@ key_event(void) | |
set_box(!ttyclock->option.box); | ||
break; | ||
|
||
case '"': | ||
case '!': | ||
case '@': | ||
case '#': | ||
case '$': | ||
case '%': | ||
case '^': | ||
case '&': | ||
case '*': | ||
case '(': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do we use shift here? this is bound to fail depending on the keyboard mapping... why not just use the normal digits? |
||
while ( p < 9 && nums[p] != c ) p++; | ||
if (c == '"') | ||
p = 2; | ||
set_position(p); | ||
break; | ||
default: | ||
nanosleep(&length, NULL); | ||
for(i = 0; i < 8; ++i) | ||
|
@@ -563,13 +619,13 @@ main(int argc, char **argv) | |
|
||
atexit(cleanup); | ||
|
||
while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:")) != -1) | ||
while ((c = getopt(argc, argv, "iuvsScbtrhBxnDC:f:d:T:a:p:")) != -1) | ||
{ | ||
switch(c) | ||
{ | ||
case 'h': | ||
default: | ||
printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] \n" | ||
printf("usage : tty-clock [-iuvsScbtrahDBxn] [-C [0-7]] [-f format] [-d delay] [-a nsdelay] [-T tty] [-p [1-9]] \n" | ||
" -s Show seconds \n" | ||
" -S Screensaver mode \n" | ||
" -x Show box \n" | ||
|
@@ -588,7 +644,8 @@ main(int argc, char **argv) | |
" -D Hide date \n" | ||
" -B Enable blinking colon \n" | ||
" -d delay Set the delay between two redraws of the clock. Default 1s. \n" | ||
" -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns.\n"); | ||
" -a nsdelay Additional delay between two redraws in nanoseconds. Default 0ns.\n" | ||
" -p [1-9] Position of clock in terminal: 1-9 starting top-left and ending bottom-right.\n"); | ||
exit(EXIT_SUCCESS); | ||
break; | ||
case 'i': | ||
|
@@ -644,6 +701,10 @@ main(int argc, char **argv) | |
case 'x': | ||
ttyclock->option.box = True; | ||
break; | ||
case 'p': | ||
if(atol(optarg) > 0 && atol(optarg) < 10) | ||
ttyclock->option.position = atol(optarg); | ||
break; | ||
case 'T': { | ||
struct stat sbuf; | ||
if (stat(optarg, &sbuf) == -1) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"starting top-left and ending bottom-right"... how do we get to "bottom left"? :)
i guess we want to say something like "starting clockwise from the top-left" or something like that.
should we make 0 be "center" and remove the other flag? ;)