Skip to content

Commit

Permalink
Improved window flag handling and set cursor always enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
palomena committed Dec 28, 2021
1 parent 11c032a commit 100eb8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ all:
cc ./src/*.c -o./build/sdlterm ${CFLAGS}

clean:
rm -rv ./build
rm -rv ./build

install:
sudo cp -v ./build/sdlterm /usr/local/bin
21 changes: 16 additions & 5 deletions src/sdlterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ static void swap(int *a, int *b);
/*****************************************************************************/

int damage(VTermRect rect, void *user) {
//printf("damage: [%d, %d, %d, %d]\n", rect.start_col,
// rect.start_row, rect.end_col, rect.end_row);
return 1;
}
int moverect(VTermRect dest, VTermRect src, void *user) {
Expand All @@ -173,7 +175,8 @@ int movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user) {
state->cursor.position.x = pos.col;
state->cursor.position.y = pos.row;
if(visible == 0) {
state->cursor.active = false;
// Works great for 'top' but not for 'nano'. Nano should have a cursor!
//state->cursor.active = false;
} else state->cursor.active = true;
return 1;
}
Expand All @@ -197,7 +200,8 @@ int sb_popline(int cols, VTermScreenCell *cells, void *user) {
VTermScreenCallbacks callbacks = {
.movecursor = movecursor,
.sb_pushline = sb_pushline,
.bell = bell
.bell = bell,
.damage = damage
};

int main(int argc, char *argv[]) {
Expand All @@ -221,7 +225,7 @@ int main(int argc, char *argv[]) {
if(TERM_InitializeTerminal(&state, &cfg)) return -1;
while(!TERM_HandleEvents(&state)) {
TERM_Update(&state);
SDL_Delay(10);
SDL_Delay(20);
}

TERM_DeinitializeTerminal(&state);
Expand Down Expand Up @@ -357,9 +361,16 @@ int TERM_InitializeTerminal(TERM_State *state, TERM_Config *cfg) {
return -1;
}

Uint32 wflags = TERM_GetWindowFlags(cfg);
if(wflags & SDL_WINDOW_FULLSCREEN) {
/* Override resolution with display fullscreen resolution */
SDL_Rect rect;
SDL_GetDisplayBounds(0, &rect);
cfg->width = rect.w;
cfg->height = rect.h;
}
state->window = SDL_CreateWindow(PROGNAME, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, cfg->width, cfg->height,
TERM_GetWindowFlags(cfg));
SDL_WINDOWPOS_CENTERED, cfg->width, cfg->height, wflags);
if(state->window == NULL) {
return -1;
}
Expand Down

0 comments on commit 100eb8f

Please sign in to comment.