mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
Add very basic KeyDown events to the GUI event stream.
The Terminal program now hosts an interactive shell. :^)
This commit is contained in:
parent
c0ef060a7c
commit
78696236d3
4 changed files with 33 additions and 8 deletions
|
@ -42,11 +42,18 @@ struct GUI_WindowBackingStoreInfo {
|
||||||
|
|
||||||
enum class GUI_MouseButton : unsigned char {
|
enum class GUI_MouseButton : unsigned char {
|
||||||
NoButton = 0,
|
NoButton = 0,
|
||||||
Left = 1,
|
Left = 1,
|
||||||
Right = 2,
|
Right = 2,
|
||||||
Middle = 4,
|
Middle = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GUI_KeyModifiers { enum {
|
||||||
|
Shift = 1 << 0,
|
||||||
|
Alt = 1 << 1,
|
||||||
|
Ctrl = 1 << 2,
|
||||||
|
}; };
|
||||||
|
|
||||||
|
|
||||||
struct GUI_Event {
|
struct GUI_Event {
|
||||||
enum Type : unsigned {
|
enum Type : unsigned {
|
||||||
Invalid,
|
Invalid,
|
||||||
|
@ -54,6 +61,8 @@ struct GUI_Event {
|
||||||
MouseMove,
|
MouseMove,
|
||||||
MouseDown,
|
MouseDown,
|
||||||
MouseUp,
|
MouseUp,
|
||||||
|
KeyDown,
|
||||||
|
KeyUp,
|
||||||
};
|
};
|
||||||
Type type { Invalid };
|
Type type { Invalid };
|
||||||
int window_id { -1 };
|
int window_id { -1 };
|
||||||
|
@ -66,6 +75,10 @@ struct GUI_Event {
|
||||||
GUI_Point position;
|
GUI_Point position;
|
||||||
GUI_MouseButton button;
|
GUI_MouseButton button;
|
||||||
} mouse;
|
} mouse;
|
||||||
|
struct {
|
||||||
|
char character;
|
||||||
|
unsigned modifiers;
|
||||||
|
} key;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1173,6 +1173,7 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
return descriptor->file_flags();
|
return descriptor->file_flags();
|
||||||
case F_SETFL:
|
case F_SETFL:
|
||||||
|
// FIXME: Support changing O_NONBLOCK
|
||||||
descriptor->set_file_flags(arg);
|
descriptor->set_file_flags(arg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1294,6 +1295,8 @@ int Process::sys$open(const char* path, int options)
|
||||||
return error;
|
return error;
|
||||||
if (options & O_DIRECTORY && !descriptor->is_directory())
|
if (options & O_DIRECTORY && !descriptor->is_directory())
|
||||||
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
||||||
|
if (options & O_NONBLOCK)
|
||||||
|
descriptor->set_blocking(false);
|
||||||
|
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
for (; fd < (int)m_max_open_file_descriptors; ++fd) {
|
for (; fd < (int)m_max_open_file_descriptors; ++fd) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ static void make_shell(int ptm_fd)
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
int ptm_fd = open("/dev/ptm0", O_RDWR);
|
int ptm_fd = open("/dev/ptm0", O_RDWR | O_NONBLOCK);
|
||||||
if (ptm_fd < 0) {
|
if (ptm_fd < 0) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -53,7 +53,7 @@ int main(int, char**)
|
||||||
|
|
||||||
make_shell(ptm_fd);
|
make_shell(ptm_fd);
|
||||||
|
|
||||||
int event_fd = open("/dev/gui_events", O_RDONLY);
|
int event_fd = open("/dev/gui_events", O_RDONLY | O_NONBLOCK);
|
||||||
if (event_fd < 0) {
|
if (event_fd < 0) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -72,13 +72,15 @@ int main(int, char**)
|
||||||
}
|
}
|
||||||
terminal.paint();
|
terminal.paint();
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
GUI_Event event;
|
GUI_Event event;
|
||||||
ssize_t nread = read(event_fd, &event, sizeof(event));
|
ssize_t nread = read(event_fd, &event, sizeof(event));
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (nread == 0)
|
||||||
|
continue;
|
||||||
assert(nread == sizeof(event));
|
assert(nread == sizeof(event));
|
||||||
dbgprintf("(Terminal:%d) ", getpid());
|
dbgprintf("(Terminal:%d) ", getpid());
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
|
@ -86,13 +88,16 @@ int main(int, char**)
|
||||||
case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
case GUI_Event::Type::MouseDown: dbgprintf("WID=%x MouseDown %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
||||||
case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
case GUI_Event::Type::MouseUp: dbgprintf("WID=%x MouseUp %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
||||||
case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
case GUI_Event::Type::MouseMove: dbgprintf("WID=%x MouseMove %d,%d\n", event.window_id, event.mouse.position.x, event.mouse.position.y); break;
|
||||||
|
case GUI_Event::Type::KeyDown: dbgprintf("WID=%x KeyDown 0x%b (%c)\n", event.window_id, event.key.character, event.key.character); break;
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == GUI_Event::Type::MouseDown)
|
if (event.type == GUI_Event::Type::Paint) {
|
||||||
terminal.paint();
|
terminal.paint();
|
||||||
#endif
|
} else if (event.type == GUI_Event::Type::KeyDown) {
|
||||||
|
write(ptm_fd, &event.key.character, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,10 @@ void Window::event(Event& event)
|
||||||
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
|
gui_event.mouse.position = static_cast<MouseEvent&>(event).position();
|
||||||
gui_event.mouse.button = to_api(static_cast<MouseEvent&>(event).button());
|
gui_event.mouse.button = to_api(static_cast<MouseEvent&>(event).button());
|
||||||
break;
|
break;
|
||||||
|
case Event::KeyDown:
|
||||||
|
gui_event.type = GUI_Event::Type::KeyDown;
|
||||||
|
gui_event.key.character = static_cast<KeyEvent&>(event).text()[0];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gui_event.type == GUI_Event::Type::Invalid)
|
if (gui_event.type == GUI_Event::Type::Invalid)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue