mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-03-12 07:04:28 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9dbee9993 | ||
|
|
740445f425 | ||
|
|
f849e85e9f | ||
|
|
628b131741 |
@@ -29,6 +29,7 @@ src = [
|
||||
'src/util/process.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/term.c',
|
||||
'src/util/thread.c',
|
||||
'src/util/tick.c',
|
||||
]
|
||||
@@ -189,6 +190,7 @@ if get_option('buildtype') == 'debug'
|
||||
'src/options.c',
|
||||
'src/util/strbuf.c',
|
||||
'src/util/str_util.c',
|
||||
'src/util/term.c',
|
||||
]],
|
||||
['test_clock', [
|
||||
'tests/test_clock.c',
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "options.h"
|
||||
#include "util/log.h"
|
||||
#include "util/strbuf.h"
|
||||
#include "util/str_util.h"
|
||||
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "util/term.h"
|
||||
|
||||
#define STR_IMPL_(x) #x
|
||||
#define STR(x) STR_IMPL_(x)
|
||||
@@ -743,13 +742,16 @@ print_shortcut(const struct sc_shortcut *shortcut, unsigned cols) {
|
||||
|
||||
void
|
||||
scrcpy_print_usage(const char *arg0) {
|
||||
unsigned cols = 80;
|
||||
#define SC_TERM_COLS_DEFAULT 80
|
||||
unsigned cols;
|
||||
|
||||
struct winsize ws;
|
||||
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) != -1) {
|
||||
cols = ws.ws_col;
|
||||
if (cols < 20) {
|
||||
cols = 20;
|
||||
if (!isatty(STDERR_FILENO)) {
|
||||
// Not a tty, use a default value
|
||||
cols = SC_TERM_COLS_DEFAULT;
|
||||
} else {
|
||||
bool ok = sc_term_get_size(NULL, &cols);
|
||||
if (!ok) {
|
||||
cols = SC_TERM_COLS_DEFAULT; // default value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
51
app/src/util/term.c
Normal file
51
app/src/util/term.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "term.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
bool
|
||||
sc_term_get_size(unsigned *rows, unsigned *cols) {
|
||||
#ifdef _WIN32
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
bool ok =
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rows) {
|
||||
assert(csbi.srWindow.Bottom >= csbi.srWindow.Top);
|
||||
*rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
||||
}
|
||||
|
||||
if (cols) {
|
||||
assert(csbi.srWindow.Right >= csbi.srWindow.Left);
|
||||
*cols = csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
struct winsize ws;
|
||||
int r = ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
|
||||
if (r == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rows) {
|
||||
*rows = ws.ws_row;
|
||||
}
|
||||
|
||||
if (cols) {
|
||||
*cols = ws.ws_col;
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
11
app/src/util/term.h
Normal file
11
app/src/util/term.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef SC_TERM_H
|
||||
#define SC_TERM_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool
|
||||
sc_term_get_size(unsigned *rows, unsigned *cols);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user