mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-25 09:59:00 +01:00
Added significant number of new request types.
This commit is contained in:
parent
3dd9f85468
commit
a5ca257272
4 changed files with 246 additions and 17 deletions
|
@ -86,6 +86,8 @@ module X11
|
|||
return Form::KeyRelease.from_packet(StringIO.new(data))
|
||||
when 4
|
||||
return Form::ButtonPress.from_packet(StringIO.new(data))
|
||||
when 5
|
||||
return Form::ButtonRelease.from_packet(StringIO.new(data))
|
||||
when 6
|
||||
return Form::MotionNotify.from_packet(StringIO.new(data))
|
||||
when 12
|
||||
|
@ -177,9 +179,46 @@ module X11
|
|||
end
|
||||
end
|
||||
|
||||
def find_visual(screen, depth, qlass = 4)
|
||||
self.display_info.screens[screen].depths.find{|d|
|
||||
d.depth == depth }.visuals.find{|v| v.qlass = qlass }
|
||||
end
|
||||
|
||||
# Requests
|
||||
def create_window(*args)
|
||||
write_request(X11::Form::CreateWindow.new(*args))
|
||||
def create_window(x,y,w,h,
|
||||
values: {},
|
||||
depth: 32, parent: nil, border_width: 0, wclass: X11::Form::InputOutput, visual: nil
|
||||
)
|
||||
wid = new_id
|
||||
parent ||= screens.first.root
|
||||
|
||||
|
||||
if visual.nil?
|
||||
visual = find_visual(0, depth).visual_id
|
||||
end
|
||||
|
||||
|
||||
values[X11::Form::CWColorMap] ||= create_colormap(0, parent, visual)
|
||||
|
||||
values = values.sort_by{_1[0]}
|
||||
mask = values.inject(0) {|acc,v| (acc | v[0]) }
|
||||
values = values.map{_1[1]}
|
||||
write_request(
|
||||
X11::Form::CreateWindow.new(
|
||||
depth, wid, parent,
|
||||
x,y,w,h,border_width, wclass, visual, mask, values)
|
||||
)
|
||||
return wid
|
||||
end
|
||||
|
||||
def change_window_attributes(wid,
|
||||
values: {})
|
||||
values = values.sort_by{_1[0]}
|
||||
mask = values.inject(0) {|acc,v| (acc | v[0]) }
|
||||
values = values.map{_1[1]}
|
||||
write_request(
|
||||
X11::Form::ChangeWindowAttributes.new(wid, mask, values)
|
||||
)
|
||||
end
|
||||
|
||||
def atom(name)
|
||||
|
@ -211,6 +250,14 @@ module X11
|
|||
end
|
||||
end
|
||||
|
||||
def destroy_window(window)
|
||||
write_request(X11::Form::DestroyWindow.new(window))
|
||||
end
|
||||
|
||||
def get_geometry(drawable)
|
||||
write_sync(X11::Form::GetGeometry.new(drawable), X11::Form::Geometry)
|
||||
end
|
||||
|
||||
def get_keyboard_mapping(min_keycode=display_info.min_keycode, count= display_info.max_keycode - min_keycode)
|
||||
write_sync(X11::Form::GetKeyboardMapping.new(min_keycode, count), X11::Form::GetKeyboardMappingReply)
|
||||
end
|
||||
|
@ -242,6 +289,77 @@ module X11
|
|||
write_request(X11::Form::MapWindow.new(*args))
|
||||
end
|
||||
|
||||
def grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode)
|
||||
write_request(X11::Form::GrabKey.new(
|
||||
owner_events,
|
||||
grab_window,
|
||||
modifiers,
|
||||
keycode,
|
||||
pointer_mode == :async ? 1 : 0,
|
||||
keyboard_mode == :async ? 1 : 0
|
||||
))
|
||||
end
|
||||
|
||||
def grab_button(owner_events, grab_window, event_mask, pointer_mode,
|
||||
keyboard_mode, confine_to, cursor, button, modifiers)
|
||||
write_request(X11::Form::GrabButton.new(
|
||||
owner_events, grab_window, event_mask,
|
||||
pointer_mode == :async ? 1 : 0,
|
||||
keyboard_mode == :async ? 1 : 0,
|
||||
confine_to.to_i, cursor.to_i, button, modifiers)
|
||||
)
|
||||
end
|
||||
|
||||
def configure_window(window, x: nil, y: nil, width: nil, height: nil,
|
||||
border_width: nil, sibling: nil, stack_mode: nil)
|
||||
|
||||
mask = 0
|
||||
values = []
|
||||
|
||||
if x
|
||||
mask |= 0x001
|
||||
values << x
|
||||
end
|
||||
|
||||
if y
|
||||
mask |= 0x002
|
||||
values << y
|
||||
end
|
||||
|
||||
if width
|
||||
mask |= 0x004
|
||||
values << width
|
||||
end
|
||||
|
||||
if height
|
||||
mask |= 0x008
|
||||
values << height
|
||||
end
|
||||
|
||||
if border_width
|
||||
mask |= 0x010
|
||||
values << border_width
|
||||
end
|
||||
|
||||
if sibling
|
||||
mask |= 0x020
|
||||
values << sibling
|
||||
end
|
||||
|
||||
if stack_mode
|
||||
mask |= 0x040
|
||||
values << case stack_mode
|
||||
when :above then 0
|
||||
when :below then 1
|
||||
when :top_if then 2
|
||||
when :bottom_if then 3
|
||||
when :opposite then 4
|
||||
else raise "Unknown stack_mode #{stack_mode.inspect}"
|
||||
end
|
||||
end
|
||||
write_request(X11::Form::ConfigureWindow.new(window, mask, values))
|
||||
end
|
||||
|
||||
|
||||
def create_gc(window, foreground: nil, background: nil)
|
||||
mask = 0
|
||||
|
@ -329,7 +447,7 @@ module X11
|
|||
s.depths.map do |d|
|
||||
d.visuals.map {|v| v.visual == visual ? v : nil }
|
||||
end
|
||||
end.flatten.compact.first.format
|
||||
end.flatten.compact.first&.format
|
||||
end
|
||||
|
||||
def render_find_standard_format(sym)
|
||||
|
|
130
lib/X11/form.rb
130
lib/X11/form.rb
|
@ -332,14 +332,26 @@ module X11
|
|||
InputOutput = 1
|
||||
InputOnly = 2
|
||||
|
||||
CWBackPixel = 0x0002
|
||||
CWBackPixmap = 0x0001
|
||||
CWBackPixel = 0x0002
|
||||
CWBorderPixmap= 0x0004
|
||||
CWBorderPixel = 0x0008
|
||||
CWEventMask = 0x0800
|
||||
CWColorMap = 0x2000
|
||||
CWBitGravity = 0x0010
|
||||
CWWinGravity = 0x0020
|
||||
CWBackingStore= 0x0040
|
||||
CWSaveUnder = 0x0400
|
||||
CWEventMask = 0x0800
|
||||
CWColorMap = 0x2000
|
||||
|
||||
KeyPressMask = 0x00001
|
||||
KeyReleaseMask = 0x00002
|
||||
ButtonPressMask = 0x00004
|
||||
ButtonReleaseMask = 0x00008
|
||||
EnterWindowMask = 0x00010
|
||||
LeaveWindowMask = 0x00020
|
||||
PointerMotionMask = 0x00040
|
||||
PointerMotionHintMask = 0x00080
|
||||
Button1MotionMask = 0x00100
|
||||
ExposureMask = 0x08000
|
||||
StructureNotifyMask = 0x20000
|
||||
SubstructureNotifyMask = 0x80000
|
||||
|
@ -361,6 +373,51 @@ module X11
|
|||
field :value_list, Uint32, :list
|
||||
end
|
||||
|
||||
class ChangeWindowAttributes < BaseForm
|
||||
field :opcode, Uint8, value: 2
|
||||
unused 1
|
||||
field :request_length, Uint16, value: ->(cw) { 3 + cw.value_list.length }
|
||||
field :window, Window
|
||||
field :value_mask, Bitmask
|
||||
field :value_list, Uint32, :list
|
||||
end
|
||||
|
||||
class GetWindowAttributes < BaseForm
|
||||
field :opcode, Uint8, value: 3
|
||||
unused 1
|
||||
field :request_length, Uint16, value: 2
|
||||
field :window, Window
|
||||
end
|
||||
|
||||
class WindowAttributes < BaseForm
|
||||
field :reply, Uint8, value: 1
|
||||
field :backing_store, Uint8
|
||||
field :sequence_number, Uint16
|
||||
field :reply_length, Uint32
|
||||
field :visual, VisualID
|
||||
field :class, Uint16
|
||||
field :bit_gravity, Uint8
|
||||
field :win_gravity, Uint8
|
||||
field :backing_planes, Uint32
|
||||
field :backing_pixel, Uint32
|
||||
field :save_under, Bool
|
||||
field :map_is_installed, Bool
|
||||
field :map_state, Bool
|
||||
field :override_redirect, Bool
|
||||
field :colormap, Colormap
|
||||
field :all_event_masks, Uint32
|
||||
field :your_event_masks, Uint32
|
||||
field :do_not_propagate_mask, Uint16
|
||||
unused 2
|
||||
end
|
||||
|
||||
class DestroyWindow < BaseForm
|
||||
field :opcode, Uint8, value: 4
|
||||
unused 1
|
||||
field :request_length, Uint16, value: 2
|
||||
field :window, Window
|
||||
end
|
||||
|
||||
class MapWindow < BaseForm
|
||||
field :opcode, Uint8, value: 8
|
||||
unused 1
|
||||
|
@ -368,6 +425,37 @@ module X11
|
|||
field :window, Window
|
||||
end
|
||||
|
||||
class ConfigureWindow < BaseForm
|
||||
field :opcode, Uint8, value: 12
|
||||
unused 1
|
||||
field :request_length, Uint16, value: ->(cw) { 3 + cw.values.length }
|
||||
field :window, Window
|
||||
field :value_mask, Uint16
|
||||
unused 2
|
||||
field :values, Uint32, :list
|
||||
end
|
||||
|
||||
class GetGeometry < BaseForm
|
||||
field :opcode, Uint8, value: 14
|
||||
unused 1
|
||||
field :request_length, Uint16, value: 2
|
||||
field :drawable, Drawable
|
||||
end
|
||||
|
||||
class Geometry < BaseForm
|
||||
field :reply, Uint8, value: 1
|
||||
field :depth, Uint8
|
||||
field :sequence_number, Uint16
|
||||
field :reply_length, Uint32
|
||||
field :root, Window
|
||||
field :x, Int16
|
||||
field :y, Int16
|
||||
field :width, Uint16
|
||||
field :height, Uint16
|
||||
field :border_width, Uint16
|
||||
unused 10
|
||||
end
|
||||
|
||||
class InternAtom < BaseForm
|
||||
field :opcode, Uint8, value: 16
|
||||
field :only_if_exists, Bool
|
||||
|
@ -415,16 +503,31 @@ module X11
|
|||
field :data, Uint8, :list
|
||||
end
|
||||
|
||||
class OpenFont < BaseForm
|
||||
field :opcode, Uint8, value: 45
|
||||
class GrabButton < BaseForm
|
||||
field :opcode, Uint8, value: 28
|
||||
field :owner_events, Bool
|
||||
field :request_length, Uint16, value: 6
|
||||
field :grab_window, Window
|
||||
field :event_mask, Uint16
|
||||
field :pointer_mode, Uint8
|
||||
field :keyboard_mode, Uint8
|
||||
field :confine_to, Window
|
||||
field :cursor, Cursor
|
||||
field :button, Uint8
|
||||
unused 1
|
||||
field :request_length, Uint16, value: ->(of) {
|
||||
3+(of.name.length+3)/4
|
||||
}
|
||||
field :fid, Font
|
||||
field :name, Uint16, :length
|
||||
unused 2
|
||||
field :name, String8, :string
|
||||
field :modifiers, Uint16
|
||||
end
|
||||
|
||||
class GrabKey < BaseForm
|
||||
field :opcode, Uint8, value: 33
|
||||
field :owner_event, Bool
|
||||
field :request_length, Uint16, value: 4
|
||||
field :grab_window, Window
|
||||
field :modifiers, Uint16
|
||||
field :keycode, Uint8
|
||||
field :pointer_mode, Uint8
|
||||
field :keyboard_mode, Uint8
|
||||
unused 3
|
||||
end
|
||||
|
||||
class ListFonts < BaseForm
|
||||
|
@ -677,6 +780,9 @@ module X11
|
|||
|
||||
class MotionNotify < PressEvent
|
||||
end
|
||||
|
||||
class ButtonRelease < PressEvent
|
||||
end
|
||||
|
||||
class Expose < SimpleEvent
|
||||
field :window, Window
|
||||
|
|
|
@ -114,13 +114,18 @@ module X11
|
|||
0xff9d => :XK_KP_Begin,
|
||||
0xff9e => :XK_KP_Insert,
|
||||
0xff9f => :XK_KP_Delete,
|
||||
0xffbd => :XK_KP_Equal,
|
||||
0xffaa => :XK_KP_Multiply,
|
||||
0xffab => :XK_KP_Add,
|
||||
0xffac => :XK_KP_Separator,
|
||||
0xffad => :XK_KP_Subtract,
|
||||
0xffae => :XK_KP_Decimal,
|
||||
0xffaf => :XK_KP_Divide,
|
||||
0xffbd => :XK_KP_Equal,
|
||||
0xffbe => :f1,
|
||||
0xffbf => :f2,
|
||||
0xffc0 => :f3,
|
||||
0xffc1 => :f4, # And so on
|
||||
|
||||
|
||||
0xffe1 => :XK_Shift_L,
|
||||
0xffe2 => :XK_Shift_R,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module X11
|
||||
VERSION = "0.0.2"
|
||||
VERSION = "0.0.4"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue