mirror of
https://github.com/vidarh/ruby-x11
synced 2024-12-27 09:59:21 +01:00
Cleanups
This commit is contained in:
parent
d7029c2441
commit
e52fb412ee
2 changed files with 62 additions and 97 deletions
|
@ -143,7 +143,7 @@ def render_glyph(display, wid, x,y, ch)
|
||||||
#p img
|
#p img
|
||||||
# p ch
|
# p ch
|
||||||
display.put_image(
|
display.put_image(
|
||||||
X11::Form::ZPixmap, wid, $gc2,
|
:ZPixmap, wid, $gc2,
|
||||||
mtx.min_width,mtx.min_height,
|
mtx.min_width,mtx.min_height,
|
||||||
x, y - mtx.y_offset, 0, depth, data
|
x, y - mtx.y_offset, 0, depth, data
|
||||||
)
|
)
|
||||||
|
@ -158,12 +158,12 @@ def render_str(display, wid, x,y, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redraw(dpy, wid, gc)
|
def redraw(dpy, wid, gc)
|
||||||
dpy.poly_fill_rectangle(wid, gc, [X11::Form::Rectangle.new(20,20, 60, 80)])
|
dpy.poly_fill_rectangle(wid, gc, [20,20, 60, 80])
|
||||||
dpy.clear_area(false, wid, 30, 30, 5, 5)
|
dpy.clear_area(false, wid, 30, 30, 5, 5)
|
||||||
dpy.image_text16(wid, $gc2, 30, 70, "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ")
|
dpy.image_text16(wid, $gc2, 30, 70, "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ")
|
||||||
#"\u25f0\u25ef Hello World")
|
#"\u25f0\u25ef Hello World")
|
||||||
dpy.put_image(
|
dpy.put_image(
|
||||||
X11::Form::ZPixmap, wid, $gc2,
|
:ZPixmap, wid, $gc2,
|
||||||
$png.width, $png.height, 80, 120, 0, 24, $data
|
$png.width, $png.height, 80, 120, 0, 24, $data
|
||||||
)
|
)
|
||||||
render_str(dpy, wid, 30,90, 'HelloWorld')
|
render_str(dpy, wid, 30,90, 'HelloWorld')
|
||||||
|
|
|
@ -116,7 +116,7 @@ module X11
|
||||||
# FIXME: 30: SelectionRequest
|
# FIXME: 30: SelectionRequest
|
||||||
# FIXME: 31: SelectionNotify
|
# FIXME: 31: SelectionNotify
|
||||||
# FIXME: 32: ColormapNotify
|
# FIXME: 32: ColormapNotify
|
||||||
when 33 then return Form::ClientMessage.from_packet(StringIO.new(data))
|
when 33 then return Form::ClientMessage.from_packet(io)
|
||||||
# FIXME: 34: MappingNotify
|
# FIXME: 34: MappingNotify
|
||||||
else
|
else
|
||||||
STDERR.puts "FIXME: Event: #{type}"
|
STDERR.puts "FIXME: Event: #{type}"
|
||||||
|
@ -165,11 +165,7 @@ module X11
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_request ob
|
def write_request ob
|
||||||
#p data
|
|
||||||
#p [:write_request, @requestseq, ob.class]
|
|
||||||
data = ob.to_packet if ob.respond_to?(:to_packet)
|
data = ob.to_packet if ob.respond_to?(:to_packet)
|
||||||
#p [:AddGlyph,data] if ob.is_a?(X11::Form::XRenderAddGlyphs)
|
|
||||||
#p [ob.request_length.to_i*4, data.size]
|
|
||||||
raise "BAD LENGTH for #{ob.inspect} (#{ob.request_length.to_i*4} ! #{data.size} " if ob.request_length && ob.request_length.to_i*4 != data.size
|
raise "BAD LENGTH for #{ob.inspect} (#{ob.request_length.to_i*4} ! #{data.size} " if ob.request_length && ob.request_length.to_i*4 != data.size
|
||||||
write_raw_packet(data)
|
write_raw_packet(data)
|
||||||
end
|
end
|
||||||
|
@ -252,24 +248,21 @@ module X11
|
||||||
values = values.sort_by{_1[0]}
|
values = values.sort_by{_1[0]}
|
||||||
mask = values.inject(0) {|acc,v| (acc | v[0]) }
|
mask = values.inject(0) {|acc,v| (acc | v[0]) }
|
||||||
values = values.map{_1[1]}
|
values = values.map{_1[1]}
|
||||||
write_request(
|
write_request(Form::ChangeWindowAttributes.new(wid, mask, values))
|
||||||
X11::Form::ChangeWindowAttributes.new(wid, mask, values)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_input(w, events) = change_window_attributes(w, values: {Form::CWEventMask => events})
|
def select_input(w, events) = change_window_attributes(w, values: {Form::CWEventMask => events})
|
||||||
|
|
||||||
def atom(name)
|
def atom(name)
|
||||||
|
return name if name.is_a?(Integer) # Allow atom(atom_integer_or_symbol)
|
||||||
name = name.to_sym
|
name = name.to_sym
|
||||||
intern_atom(false, name) if !@atoms[name]
|
intern_atom(false, name) if !@atoms[name]
|
||||||
@atoms[name]
|
@atoms[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_extension(name)
|
def query_extension(name)
|
||||||
r = write_sync(X11::Form::QueryExtension.new(name), X11::Form::QueryExtensionReply)
|
r = write_sync(Form::QueryExtension.new(name), Form::QueryExtensionReply)
|
||||||
@extensions[name] = {
|
@extensions[name] = { major: r.major_opcode }
|
||||||
major: r.major_opcode
|
|
||||||
}
|
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,38 +275,33 @@ module X11
|
||||||
end
|
end
|
||||||
|
|
||||||
def intern_atom(flag, name)
|
def intern_atom(flag, name)
|
||||||
reply = write_sync(X11::Form::InternAtom.new(flag, name.to_s),
|
reply = write_sync(Form::InternAtom.new(flag, name.to_s),Form::InternAtomReply)
|
||||||
X11::Form::InternAtomReply)
|
|
||||||
if reply
|
if reply
|
||||||
@atoms[name.to_sym] = reply.atom
|
@atoms[name.to_sym] = reply.atom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_atom_name(atom)
|
def get_atom_name(atom) = write_sync(Form::GetAtomName.new(atom), Form::AtomName)&.name
|
||||||
reply = write_sync(X11::Form::GetAtomName.new(atom), X11::Form::AtomName)
|
def destroy_window(window) = write_request(Form::DestroyWindow.new(window))
|
||||||
reply&.name
|
def get_geometry(drawable) = write_sync(Form::GetGeometry.new(drawable), Form::Geometry)
|
||||||
end
|
|
||||||
|
|
||||||
def destroy_window(window) = write_request(X11::Form::DestroyWindow.new(window))
|
|
||||||
def get_geometry(drawable) = write_sync(X11::Form::GetGeometry.new(drawable), X11::Form::Geometry)
|
|
||||||
|
|
||||||
def get_keyboard_mapping(min_keycode=display_info.min_keycode, count= display_info.max_keycode - min_keycode)
|
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)
|
write_sync(Form::GetKeyboardMapping.new(min_keycode, count), Form::GetKeyboardMappingReply)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_colormap(alloc, window, visual)
|
def create_colormap(alloc, window, visual)
|
||||||
mid = new_id
|
mid = new_id
|
||||||
write_request(X11::Form::CreateColormap.new(alloc, mid, window, visual))
|
write_request(Form::CreateColormap.new(alloc, mid, window, visual))
|
||||||
mid
|
mid
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_property(window, property, type, offset: 0, length: 4, delete: false)
|
def get_property(window, property, type, offset: 0, length: 4, delete: false)
|
||||||
property = atom(property) if !property.is_a?(Integer)
|
property = atom(property)
|
||||||
type = atom_enum(type)
|
type = atom_enum(type)
|
||||||
|
|
||||||
result = write_sync(X11::Form::GetProperty.new(
|
result = write_sync(Form::GetProperty.new(
|
||||||
delete, window, property, type, offset, length
|
delete, window, property, type, offset, length
|
||||||
), X11::Form::Property)
|
), Form::Property)
|
||||||
|
|
||||||
if result && result.format != 0
|
if result && result.format != 0
|
||||||
case result.format
|
case result.format
|
||||||
|
@ -335,25 +323,22 @@ module X11
|
||||||
|
|
||||||
mode = open_enum(mode, {replace: 0, prepend: 1, append: 2})
|
mode = open_enum(mode, {replace: 0, prepend: 1, append: 2})
|
||||||
type = atom_enum(type)
|
type = atom_enum(type)
|
||||||
write_request(X11::Form::ChangeProperty.new(mode, window, property, type, format, data))
|
write_request(Form::ChangeProperty.new(mode, window, property, type, format, data))
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_fonts(*args)
|
def list_fonts(...) = write_sync(Form::ListFonts.new(...), Form::ListFontsReply)
|
||||||
write_sync(X11::Form::ListFonts.new(*args),
|
def open_font(...) = write_request(Form::OpenFont.new(...))
|
||||||
X11::Form::ListFontsReply)
|
def change_gc(...) = write_request(Form::ChangeGC.new(...))
|
||||||
end
|
def change_save_set(...)= write_request(Form::ChangeSaveSet.new(...))
|
||||||
|
|
||||||
def open_font(*args) = write_request(X11::Form::OpenFont.new(*args))
|
|
||||||
def change_gc(*args) = write_request(X11::Form::ChangeGC.new(*args))
|
|
||||||
def change_save_set(...)= write_request(X11::Form::ChangeSaveSet.new(...))
|
|
||||||
def reparent_window(window, parent, x, y, save: true)
|
def reparent_window(window, parent, x, y, save: true)
|
||||||
# You so almost always want this that it should've been a single request
|
# You so almost always want this that it should've been a single request
|
||||||
change_save_set(0, window) if save
|
change_save_set(0, window) if save
|
||||||
write_request(X11::Form::ReparentWindow.new(window, parent, x,y))
|
write_request(Form::ReparentWindow.new(window, parent, x,y))
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_window(*args) = write_request(X11::Form::MapWindow.new(*args))
|
def map_window(...) = write_request(Form::MapWindow.new(...))
|
||||||
def unmap_window(*args) = write_request(X11::Form::UnmapWindow.new(*args))
|
def unmap_window(...) = write_request(Form::UnmapWindow.new(...))
|
||||||
|
|
||||||
def u8(*args) = args.pack("c*")
|
def u8(*args) = args.pack("c*")
|
||||||
def u16(*args) = args.pack("v*")
|
def u16(*args) = args.pack("v*")
|
||||||
|
@ -377,7 +362,7 @@ module X11
|
||||||
end
|
end
|
||||||
|
|
||||||
def grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode)
|
def grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode)
|
||||||
write_request(X11::Form::GrabKey.new(
|
write_request(Form::GrabKey.new(
|
||||||
owner_events,
|
owner_events,
|
||||||
grab_window,
|
grab_window,
|
||||||
modifiers,
|
modifiers,
|
||||||
|
@ -389,7 +374,7 @@ module X11
|
||||||
|
|
||||||
def grab_button(owner_events, grab_window, event_mask, pointer_mode,
|
def grab_button(owner_events, grab_window, event_mask, pointer_mode,
|
||||||
keyboard_mode, confine_to, cursor, button, modifiers)
|
keyboard_mode, confine_to, cursor, button, modifiers)
|
||||||
write_request(X11::Form::GrabButton.new(
|
write_request(Form::GrabButton.new(
|
||||||
owner_events, grab_window, event_mask,
|
owner_events, grab_window, event_mask,
|
||||||
pointer_mode == :async ? 1 : 0,
|
pointer_mode == :async ? 1 : 0,
|
||||||
keyboard_mode == :async ? 1 : 0,
|
keyboard_mode == :async ? 1 : 0,
|
||||||
|
@ -397,41 +382,27 @@ module X11
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_value(values, mask, x)
|
||||||
|
if x
|
||||||
|
values << x
|
||||||
|
mask
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def configure_window(window, x: nil, y: nil, width: nil, height: nil,
|
def configure_window(window, x: nil, y: nil, width: nil, height: nil,
|
||||||
border_width: nil, sibling: nil, stack_mode: nil)
|
border_width: nil, sibling: nil, stack_mode: nil)
|
||||||
|
|
||||||
mask = 0
|
mask = 0
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
if x
|
mask |= set_value(values, 0x001, x)
|
||||||
mask |= 0x001
|
mask |= set_value(values, 0x002, y)
|
||||||
values << x
|
mask |= set_value(values, 0x004, width)
|
||||||
end
|
mask |= set_value(values, 0x008, height)
|
||||||
|
mask |= set_value(values, 0x010, border_width)
|
||||||
if y
|
mask |= set_value(values, 0x020, sibling)
|
||||||
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
|
if stack_mode
|
||||||
mask |= 0x040
|
mask |= 0x040
|
||||||
|
@ -455,15 +426,8 @@ module X11
|
||||||
# FIXME:
|
# FIXME:
|
||||||
# The rest can be found here:
|
# The rest can be found here:
|
||||||
# https://tronche.com/gui/x/xlib/GC/manipulating.html#XGCValues
|
# https://tronche.com/gui/x/xlib/GC/manipulating.html#XGCValues
|
||||||
if foreground
|
mask |= set_value(args, 0x04, foreground)
|
||||||
mask |= 0x04
|
mask |= set_value(args, 0x08, background)
|
||||||
args << foreground
|
|
||||||
end
|
|
||||||
if background
|
|
||||||
mask |= 0x08
|
|
||||||
args << background
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
gc = new_id
|
gc = new_id
|
||||||
write_request(X11::Form::CreateGC.new(gc, window, mask, args))
|
write_request(X11::Form::CreateGC.new(gc, window, mask, args))
|
||||||
|
@ -475,12 +439,13 @@ module X11
|
||||||
def copy_area(*args) = write_request(X11::Form::CopyArea.new(*args))
|
def copy_area(*args) = write_request(X11::Form::CopyArea.new(*args))
|
||||||
def image_text8(*args) = write_request(X11::Form::ImageText8.new(*args))
|
def image_text8(*args) = write_request(X11::Form::ImageText8.new(*args))
|
||||||
def image_text16(*args)= write_request(X11::Form::ImageText16.new(*args))
|
def image_text16(*args)= write_request(X11::Form::ImageText16.new(*args))
|
||||||
def poly_fill_rectangle(*args) = write_request(X11::Form::PolyFillRectangle.new(*args))
|
def poly_fill_rectangle(wid, gc, *rects)
|
||||||
|
rects = rects.map{|r| r.is_a?(Array) ? Form::Rectangle.new(*r) : r}
|
||||||
|
write_request(X11::Form::PolyFillRectangle.new(wid, gc, rects))
|
||||||
|
end
|
||||||
|
|
||||||
def create_pixmap(depth, drawable, w,h)
|
def create_pixmap(depth, drawable, w,h)
|
||||||
pid = new_id
|
new_id.tap{|pid| write_request(Form::CreatePixmap.new(depth, pid, drawable, w,h)) }
|
||||||
write_request(X11::Form::CreatePixmap.new(depth, pid, drawable, w,h))
|
|
||||||
pid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# XRender
|
# XRender
|
||||||
|
@ -506,8 +471,8 @@ module X11
|
||||||
|
|
||||||
def render_query_pict_formats
|
def render_query_pict_formats
|
||||||
@render_formats ||= write_sync(
|
@render_formats ||= write_sync(
|
||||||
X11::Form::XRenderQueryPictFormats.new(render_opcode),
|
Form::XRenderQueryPictFormats.new(render_opcode),
|
||||||
X11::Form::XRenderQueryPictFormatsReply
|
Form::XRenderQueryPictFormatsReply
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue