Skip to content

Commit

Permalink
Improve titlebar.
Browse files Browse the repository at this point in the history
Increments-patch-version-of: ttyr-terminal
Increments-minor-version-of: ttyr-tty
  • Loading branch information
dajofrey committed Jan 8, 2024
1 parent 542088e commit 6a103de
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions build/data/misc/ttyr-tty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ttyr.tty.menu.tab:0;
ttyr.tty.menu.close:1;
ttyr.tty.menu.debug:0;
ttyr.tty.titlebar.on:0;
ttyr.tty.titlebar.color:0,0,0,255;
3 changes: 1 addition & 2 deletions src/bin/ttyr/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static ttyr_tty_TTY *TTY_p = NULL;
static int handleArgs(
int argc, char **argv_pp)
{
Args.renderer = NH_GFX_API_OPENGL; // Use OpenGL as default renderer.
Args.renderer = NH_GFX_API_OPENGL;
Args.no_unload = false;

for (int i = 1; i < argc; ++i) {
Expand Down Expand Up @@ -121,4 +121,3 @@ int main(int argc, char **argv_pp)

nh_api_terminate();
}

2 changes: 1 addition & 1 deletion src/lib/ttyr-terminal/Terminal/Grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ TTYR_TERMINAL_BEGIN()
TTYR_TERMINAL_CHECK(ttyr_terminal_updateTile(Grid_p, state_p, Update_p, update_p))
} else {
Update_p->col++;
memset(&Update_p->Glyph, 0, sizeof(ttyr_tty_Glyph));
Update_p->Glyph.codepoint = 0;
TTYR_TERMINAL_CHECK(ttyr_terminal_updateTile(Grid_p, state_p, Update_p, update_p))
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/ttyr-tty/Common/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const NH_BYTE *TTYR_TTY_SETTING_NAMES_PP[] = {
"ttyr.tty.menu.close",
"ttyr.tty.menu.debug",
"ttyr.tty.titlebar.on",
"ttyr.tty.titlebar.color",
};

size_t TTYR_TTY_SETTING_NAMES_PP_COUNT =
Expand Down Expand Up @@ -105,6 +106,13 @@ TTYR_TTY_BEGIN()
if (Values_p->size != 1) {TTYR_TTY_END(TTYR_TTY_ERROR_BAD_STATE)}
Config_p->Titlebar.on = atoi(Values_p->pp[0]);
break;
case 11 :
if (Values_p->size != 4) {TTYR_TTY_END(TTYR_TTY_ERROR_BAD_STATE)}
Config_p->Titlebar.Color.r = ((float)atoi(Values_p->pp[0]))/255.0f;
Config_p->Titlebar.Color.g = ((float)atoi(Values_p->pp[1]))/255.0f;
Config_p->Titlebar.Color.b = ((float)atoi(Values_p->pp[2]))/255.0f;
Config_p->Titlebar.Color.a = ((float)atoi(Values_p->pp[3]))/255.0f;
break;
}

TTYR_TTY_END(TTYR_TTY_SUCCESS)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ttyr-tty/Common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
TTYR_TTY_SETTING_MENU_CLOSE,
TTYR_TTY_SETTING_MENU_DEBUG,
TTYR_TTY_SETTING_TITLEBAR_ON,
TTYR_TTY_SETTING_TITLEBAR_COLOR,
} TTYR_TTY_SETTING_E;

/** @} */
Expand All @@ -51,6 +52,7 @@

typedef struct ttyr_tty_TitlebarConfig {
NH_BOOL on;
nh_Color Color;
} ttyr_tty_TitlebarConfig;

typedef struct ttyr_tty_ShellConfig {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/ttyr-tty/Common/Data/ttyr-tty.conf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ unsigned char ttyr_tty_conf_inc[] = {
0x79, 0x2e, 0x6d, 0x65, 0x6e, 0x75, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67,
0x3a, 0x30, 0x3b, 0x0a, 0x74, 0x74, 0x79, 0x72, 0x2e, 0x74, 0x74, 0x79,
0x2e, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x62, 0x61, 0x72, 0x2e, 0x6f, 0x6e,
0x3a, 0x30, 0x3b, 0x0a
0x3a, 0x30, 0x3b, 0x0a, 0x74, 0x74, 0x79, 0x72, 0x2e, 0x74, 0x74, 0x79,
0x2e, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x62, 0x61, 0x72, 0x2e, 0x63, 0x6f,
0x6c, 0x6f, 0x72, 0x3a, 0x30, 0x2c, 0x30, 0x2c, 0x30, 0x2c, 0x32, 0x35,
0x35, 0x3b, 0x0a
};
unsigned int ttyr_tty_conf_inc_len = 256;
unsigned int ttyr_tty_conf_inc_len = 291;
9 changes: 6 additions & 3 deletions src/lib/ttyr-tty/Shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,16 @@ TTYR_TTY_BEGIN()
nh_SystemTime Now = nh_core_getSystemTime();
Shell_p->Selection.doubleClick =
nh_core_getSystemTimeDiffInSeconds(Shell_p->LastClick, Now) < 0.3f;
Shell_p->Selection.draw = false;
Shell_p->Selection.draw = Shell_p->Selection.doubleClick;
Shell_p->Selection.moved = false;
Shell_p->LastClick = Now;
if (Shell_p->Selection.doubleClick) {ttyr_tty_handleShellSelection(Shell_p);}
}
if (Event.Mouse.type == NH_WSI_MOUSE_LEFT && Event.Mouse.trigger == NH_WSI_TRIGGER_RELEASE) {
Shell_p->Selection.Stop = Event.Mouse.Position;
Shell_p->Selection.stopScroll = Shell_p->scroll;
if (!Shell_p->Selection.doubleClick) {
Shell_p->Selection.Stop = Event.Mouse.Position;
Shell_p->Selection.stopScroll = Shell_p->scroll;
}
Shell_p->Selection.active = false;
Shell_p->Selection.draw = Shell_p->Selection.moved || Shell_p->Selection.doubleClick;
ttyr_tty_handleShellSelection(Shell_p);
Expand Down
11 changes: 10 additions & 1 deletion src/lib/ttyr-tty/TTY/Macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Program.h"
#include "TTY.h"
#include "SideBar.h"
#include "Titlebar.h"

#include "../Common/Macros.h"

Expand Down Expand Up @@ -465,6 +466,14 @@ TTYR_TTY_BEGIN()
TTY_p->Window_p->refreshGrid2 = NH_TRUE;
}
}

if (row == -1 && Config.Titlebar.on == true) {
// Forward titlebar hit.
if (Event.Mouse.trigger == NH_WSI_TRIGGER_PRESS) {
ttyr_tty_handleTitlebarHit(Event.Mouse, cCol);
TTY_p->Window_p->refreshGrid2 = NH_TRUE;
}
}

if (MacroTile_p == NULL || MicroTile_p == NULL) {TTYR_TTY_END(TTYR_TTY_SUCCESS)}

Expand Down Expand Up @@ -573,7 +582,7 @@ TTYR_TTY_BEGIN()
int row = -1;
ttyr_tty_translateMousePosition(((ttyr_tty_TTY*)nh_core_getWorkloadArg())->Views.pp[0], Event.Mouse, &col, &row);
if (Config.Titlebar.on) {row--;}
if (col < 0 || row < 0) {break;}
if (col < 0) {break;}
TTYR_TTY_CHECK(ttyr_tty_handleMouseInput(Window_p, Event, col, row))
break;
}
Expand Down
21 changes: 21 additions & 0 deletions src/lib/ttyr-tty/TTY/Titlebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@
//TTYR_TTY_DIAGNOSTIC_END(TTYR_TTY_SUCCESS)
//}

// INPUT ===========================================================================================

void ttyr_tty_handleTitlebarHit(
nh_wsi_MouseEvent Event, int cCol)
{
ttyr_tty_Config Config = ttyr_tty_getConfig();
if (Event.trigger == NH_WSI_TRIGGER_PRESS && cCol-1 < Config.windows) {
ttyr_tty_MacroWindow *Window_p = ttyr_tty_insertAndFocusWindow(nh_core_getWorkloadArg(), cCol-1);
Window_p->refreshGrid2 = NH_TRUE;
Window_p->refreshTitlebar = NH_TRUE;
Window_p->Tile_p->refresh = NH_TRUE;
}
}

// CHECK ===========================================================================================

void ttyr_tty_checkTitlebar(
Expand Down Expand Up @@ -96,6 +110,13 @@ TTYR_TTY_RESULT ttyr_tty_drawTitlebar(
Row_p->Glyphs_p[i].mark |= TTYR_TTY_MARK_ACCENT;
}

for (int i = 0; i < cols ; ++i) {
Row_p->Glyphs_p[i].Background.Color.r = Config.Titlebar.Color.r;
Row_p->Glyphs_p[i].Background.Color.g = Config.Titlebar.Color.g;
Row_p->Glyphs_p[i].Background.Color.b = Config.Titlebar.Color.b;
Row_p->Glyphs_p[i].Background.custom = true;
}

NH_BYTE rightSide_p[255] = {};
sprintf(rightSide_p+strlen(rightSide_p), "RAM:%.1f%%", fabs((((float)NH_SYSTEM.RAM.free)/((float)NH_SYSTEM.RAM.total))*100.0f-100.0f));

Expand Down
4 changes: 4 additions & 0 deletions src/lib/ttyr-tty/TTY/Titlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* @{
*/

void ttyr_tty_handleTitlebarHit(
nh_wsi_MouseEvent Event, int cCol
);

void ttyr_tty_checkTitlebar(
ttyr_tty_Titlebar *Titlebar_p, NH_BOOL *refresh_p
);
Expand Down

0 comments on commit 6a103de

Please sign in to comment.