mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
Add WindowActivated and WindowDeactivated events.
Use this to implement different looking Terminal cursors depending on the window active state.
This commit is contained in:
parent
135ff48bb9
commit
dad58db757
9 changed files with 66 additions and 42 deletions
|
@ -291,7 +291,8 @@ void Terminal::scroll_up()
|
|||
}
|
||||
#endif
|
||||
memset(&m_buffer[(m_rows - 1) * m_columns], ' ', m_columns);
|
||||
attribute_at(m_cursor_row, m_cursor_column).dirty = true;
|
||||
// NOTE: We have to invalidate the cursor before memcpy()'ing the attributes.
|
||||
invalidate_cursor();
|
||||
memcpy(m_attributes, m_attributes + m_columns, m_columns * (m_rows - 1) * sizeof(Attribute));
|
||||
for (size_t i = 0; i < m_columns; ++i)
|
||||
m_attributes[((m_rows - 1) * m_columns) + i].reset();
|
||||
|
@ -305,10 +306,10 @@ void Terminal::set_cursor(unsigned row, unsigned column)
|
|||
{
|
||||
ASSERT(row < rows());
|
||||
ASSERT(column < columns());
|
||||
attribute_at(m_cursor_row, m_cursor_column).dirty = true;
|
||||
invalidate_cursor();
|
||||
m_cursor_row = row;
|
||||
m_cursor_column = column;
|
||||
attribute_at(m_cursor_row, m_cursor_column).dirty = true;
|
||||
invalidate_cursor();
|
||||
}
|
||||
|
||||
void Terminal::put_character_at(unsigned row, unsigned column, byte ch)
|
||||
|
@ -449,7 +450,10 @@ void Terminal::paint()
|
|||
}
|
||||
|
||||
auto cursor_rect = glyph_rect(m_cursor_row, m_cursor_column);
|
||||
painter.draw_rect(cursor_rect, Color::MidGray);
|
||||
if (m_in_active_window)
|
||||
painter.fill_rect(cursor_rect, Color::MidGray);
|
||||
else
|
||||
painter.draw_rect(cursor_rect, Color::MidGray);
|
||||
|
||||
if (m_belling)
|
||||
painter.draw_rect(rect, Color::Red);
|
||||
|
@ -460,3 +464,17 @@ void Terminal::paint()
|
|||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::set_in_active_window(bool b)
|
||||
{
|
||||
if (m_in_active_window == b)
|
||||
return;
|
||||
m_in_active_window = b;
|
||||
invalidate_cursor();
|
||||
paint();
|
||||
}
|
||||
|
||||
void Terminal::invalidate_cursor()
|
||||
{
|
||||
attribute_at(m_cursor_row, m_cursor_column).dirty = true;
|
||||
}
|
||||
|
|
|
@ -17,11 +17,14 @@ public:
|
|||
void paint();
|
||||
void on_char(byte);
|
||||
|
||||
void set_in_active_window(bool);
|
||||
|
||||
private:
|
||||
Font& font() { return *m_font; }
|
||||
void scroll_up();
|
||||
void set_cursor(unsigned row, unsigned column);
|
||||
void put_character_at(unsigned row, unsigned column, byte ch);
|
||||
void invalidate_cursor();
|
||||
|
||||
void escape$A(const Vector<unsigned>&);
|
||||
void escape$D(const Vector<unsigned>&);
|
||||
|
@ -94,5 +97,7 @@ private:
|
|||
int m_line_spacing { 4 };
|
||||
int m_line_height { 0 };
|
||||
|
||||
bool m_in_active_window { false };
|
||||
|
||||
RetainPtr<Font> m_font;
|
||||
};
|
||||
|
|
|
@ -118,6 +118,8 @@ int main(int, char**)
|
|||
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::KeyDown: dbgprintf("WID=%x KeyDown 0x%b (%c)\n", event.window_id, event.key.character, event.key.character); break;
|
||||
case GUI_Event::Type::WindowActivated: dbgprintf("WID=%x WindowActivated\n", event.window_id); break;
|
||||
case GUI_Event::Type::WindowDeactivated: dbgprintf("WID=%x WindowDeactivated\n", event.window_id); break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
@ -126,6 +128,10 @@ int main(int, char**)
|
|||
terminal.paint();
|
||||
} else if (event.type == GUI_Event::Type::KeyDown) {
|
||||
write(ptm_fd, &event.key.character, 1);
|
||||
} else if (event.type == GUI_Event::Type::WindowActivated) {
|
||||
terminal.set_in_active_window(true);
|
||||
} else if (event.type == GUI_Event::Type::WindowDeactivated) {
|
||||
terminal.set_in_active_window(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue