-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add getcellpixels() #16004
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
Add getcellpixels() #16004
Conversation
8718e22 to
db51514
Compare
|
Thanks, but I have a few high-level comments:
|
|
OK. I try it. Since we know the cell size, it's easy to calculate the window size by combining Cell size is dependent terminal, so test is only dictionary has entries check. I will work with this implementation. |
|
A few top-level questions / comments:
|
Should this just return an array, something like |
This (https://stackoverflow.com/a/50395589/8916547) seems to provide a way to query this in Windows. |
|
@ychin Thank you for your comments!
|
No, what I mean is just use the stdin / stdout fd. I don't think there is any need to do any of the other methods to get the tty fd. In fact, did you look at the // os_unix.c
int
mch_get_shellsize(void)
{
// …
/*
* 1. try using an ioctl. It is the most accurate method.
*
* Try using TIOCGWINSZ first, some systems that have it also define
* TIOCGSIZE but don't have a struct ttysize.
*/
# ifdef TIOCGWINSZ
{
struct winsize ws;
int fd = 1;
// When stdout is not a tty, use stdin for the ioctl().
if (!isatty(fd) && isatty(read_cmd_fd))
fd = read_cmd_fd;
if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
{
columns = ws.ws_col;
rows = ws.ws_row;
# ifdef FEAT_EVAL
ch_log(NULL, "Got size with TIOCGWINSZ: %ld x %ld", columns, rows);
# endif
}
// …
}For reference, this function is used for determining the values of Another comment (just to save back-and-forth time) is we usually put function declaration in the misc |
|
Sorry, I did not study enough. |
| List format is [xpixels, ypixels]. | ||
| Only on UNIX. | ||
|
|
||
| Return type: list<any> |
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.
The document should explain that some environments may return unreliable values.
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.
On what environments would it be unreliable? I think it just needs to clearly explain that it would return an error value, e.g. -1,-1 when it's unavailable. That's not "unreliable" per se.
|
|
||
| getcellpixels() *getcellpixels()* | ||
| Returns a |List| of cell pixel size. | ||
| List format is [xpixels, ypixels]. |
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.
Only works on Unix. For gVim, returns [5, 10], on other systems, returns [-1, -1].
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.
Shouldn't gVIm return [-1,-1] until gVim gets a proper implementation?
|
Seems from the implementation that this is going to return Should we just standardize on this and fix the doc? Perhaps just returning I think the tests are also in the wrong file as well. I can submit a PR to fix it. It's put into the UTF-8 tests next to |
|
Yes makes sense to just return an empty list. and the documentation should then be changed back to |
|
Thank you for pointing out the improvement. |
|
Can not call I will fix doc and gui implementation, test position. |
|
I will create test file |
I tried the stack overflow post you suggested, but the font size was returned as a fixed value of 0x16. prototype branch: 2fb4877#diff-6e09d275741ed4a17372f6e64995645e818d605e41a0591b2c20741f4878d3c1R9074 |
Don't use `gui.char_width` / `char_height` unlike the other GVim implementations. Those are used for deriving screen pixel sizes and MacVim has been hard-coding them to 1 for simplicity since the actual GUI functionality is handled out of the Vim process anyway. Changing those values would require some refactoring. Instead, just use a new variable to store them. Related: vim/vim#16004
Don't use `gui.char_width` / `char_height` unlike the other GVim implementations. Those are used for deriving screen pixel sizes and MacVim has been hard-coding them to 1 for simplicity since the actual GUI functionality is handled out of the Vim process anyway. Changing those values would require some refactoring. Instead, just use a new variable to store them. Note that there is a delay with this method, as we only update Vim's knowledge of cell size after MacVim has received the font change message. This means if a user wants to immediately query getcellpixels() in vimrc or after changing guifont this will not work. This is a deliberate design choice to avoid having to add synchronous state query APIs to MacVim, but it's possible to change it in the future. The handling of this message did get placed in `processInput:` which means it will be picked up whenever we sleep or process messages in Vim, instead of only when waiting for keys (where most of other MacVim messages are handled in `processInputQueue`). Related: vim/vim#16004
Don't use `gui.char_width` / `char_height` unlike the other GVim implementations. Those are used for deriving screen pixel sizes and MacVim has been hard-coding them to 1 for simplicity since the actual GUI functionality is handled out of the Vim process anyway. Changing those values would require some refactoring. Instead, just use a new variable to store them. Note that there is a delay with this method, as we only update Vim's knowledge of cell size after MacVim has received the font change message. This means if a user wants to immediately query getcellpixels() in vimrc or after changing guifont this will not work. This is a deliberate design choice to avoid having to add synchronous state query APIs to MacVim, but it's possible to change it in the future. The handling of this message did get placed in `processInput:` which means it will be picked up whenever we sleep or process messages in Vim, instead of only when waiting for keys (where most of other MacVim messages are handled in `processInputQueue`). Related: vim/vim#16004
What I want to do?
I want to get the pixel size of the window in the CUI version of Vim.
Motivation:
The ability to output Sixel in echoraw has opened up possibilities such as image display plugins
If the pixel size of the window can be known, the possibilities for functions such as fitting the image to the window will be expanded.
Pros:
The ability to obtain precise pixel size opens up possibilities for image output plugins.
Cons:
Even in cases where the matrix level is sufficient, processing time to obtain pixel level values is added.
Implementation:
Others:
The initial implementation used CSI escape sequences, but it was changed to the
TIOCSWINSZimplementation because of a problem where processing would not continue unless<Enter>was pressed aftergetwinsize().(See: master...mikoto2000:vim:add-pixel-size-in-getwininfo2)