Skip to content

Commit

Permalink
Make Gdk::ModifierType#none? work when there's hidden reserved valu…
Browse files Browse the repository at this point in the history
…es in the flag.
  • Loading branch information
hugopl committed Apr 10, 2022
1 parent 34dc657 commit c6a75de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/gdk_modifier_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "./spec_helper"

describe Gdk::ModifierType do
it "can be generated from value with internal data" do
flag = Gdk::ModifierType.new(16)
flag.none?.should eq(true)
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require "spec"
require "../src/gtk4"
4 changes: 4 additions & 0 deletions src/bindings/gdk/binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace: Gdk
version: "4.0"
include:
- modifier_type.cr
14 changes: 14 additions & 0 deletions src/bindings/gdk/modifier_type.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Gdk
enum ModifierType
def none?
# From GDK docs:
#
# Note that GDK may add internal values to events which include reserved values such as
# GDK_MODIFIER_RESERVED_13_MASK. Your code should preserve and ignore them. You can use
# GDK_MODIFIER_MASK to remove all reserved values.
#
# We need this so `.none?` works as expected when there's hidden values in the enum
(value & MODIFIER_MASK).zero?
end
end
end

0 comments on commit c6a75de

Please sign in to comment.